/// <summary> /// Handle the directory. /// </summary> /// <param name="directory"></param> protected virtual void HandleDirectory(DirectoryInfo directory) { FileCleanArgs args = Settings.ArgsReciever as FileCleanArgs; if (!args.DryRun) { _buffer.Append("rmdir \"" + directory.FullName + "\" /s /q" + Environment.NewLine); } else { _buffer.Append("Dry run - cleaning : " + directory.FullName + " /s /q " + Environment.NewLine); } }
/// <summary> /// Handle the file. /// </summary> /// <param name="file"></param> protected virtual void HandleFile(FileInfo file) { FileCleanArgs args = Settings.ArgsReciever as FileCleanArgs; if (!args.DryRun) { _buffer.Append("del \"" + file.FullName + "\" /f /q" + Environment.NewLine); } else { _buffer.Append("Dry run - cleaning : " + file.FullName + " /f /q" + Environment.NewLine); } }
/// <summary> /// Execute cleaning of files/directories. /// Doesn't actually delete anything but generates a file /// containing the commands. /// </summary> /// <param name="args"></param> /// <returns></returns> public override BoolMessageItem Execute(object context) { FileCleanArgs args = Settings.ArgsReciever as FileCleanArgs; // Initialize the starting directory. InitializeDir(args.RootDir); StringBuilder buffer = new StringBuilder(); bool handleFiles = true; if (args.FileType == "dir") { handleFiles = false; } FileSearcher searcher = new FileSearcher(new Action <FileInfo>(HandleFile), new Action <DirectoryInfo>(HandleDirectory), "**/**", handleFiles); searcher.Search(_rootDirectory); File.WriteAllText(args.OutputFile, _buffer.ToString()); return(new BoolMessageItem(null, true, string.Empty)); }