public void Delete(Parameters parameters) { if (LongDirectory.Exists(Path)) { string[] paths = LongDirectory.GetFiles(Path); foreach (string filePath in paths) { if (parameters.Verbose) { Console.Out.WriteLine("{0}", filePath); } LongFile.Delete(filePath); } if (parameters.Recursive) { string[] subDirs = LongDirectory.GetDirectories(Path); foreach (string subDir in subDirs) { PFolder pFolder = new PFolder(subDir); pFolder.Delete(parameters); } } if (parameters.Verbose) { Console.Out.WriteLine("{0}", Path); } LongDirectory.Delete(Path); } else if (LongFile.Exists(Path)) { if (parameters.Verbose) { Console.Out.WriteLine("{0}", Path); } LongFile.Delete(Path); } if (Path == parameters.Path) { if (parameters.RequireEnterToExit) { Console.Out.WriteLine("Press enter to exit"); Console.In.ReadLine(); } } }
static int Main(string[] args) { try { Parameters parameters = new Parameters(args); if (!parameters.Valid) { Console.Out.WriteLine(Parameters.Syntax); return(1); } else { PFolder folder = new PFolder(parameters.Path); folder.Delete(parameters); } } catch (InvalidParameterException ex) { Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(Parameters.Syntax); return(1); } return(0); }