public void Search_File() { string path = Action.path; if (Glob.HasGlobPattern(path)) { IEnumerable <string> files = Glob.GetMatches(path, Glob.Constants.PathName); string[] _files = new List <string>(files).ToArray(); path = _files.Length > 0 ? _files[0] : null; } if (path != null) { FileInfo fi = new FileInfo(path); if (fi.Exists) { if (!IsWhitelisted(fi.FullName)) { ProgressWorker.I.EnQ("Queueing file: " + fi.FullName); // enqueue file for deletion Worker.I.EnqueTTD(new Model_ThingsToDelete() { FullPathName = Action.path, IsWhitelisted = false, OverWrite = false, WhatKind = THINGS_TO_DELETE.file, command = COMMANDS.delete, search = SEARCH.file, path = string.Empty, level = Action.parent_option.level, cleaner_name = Action.parent_option.label }); } } } }
/// <summary> /// /// </summary> /// <param name="include_dir"></param> /// <param name="regex"></param> public void Search_Walk(bool include_dir = false, string regex = null) { string path = Action.path; List <string> list_paths = new List <string>(); // check glob path { string rev_slash = path.Replace('\\', '/'); if (Glob.HasGlobPattern(rev_slash)) { IEnumerable <string> paths = Glob.GetMatches(rev_slash, Glob.Constants.IgnoreCase); // since we have glob in our path // let's take that off list_paths.Clear(); // add insert a new ones list_paths.AddRange(paths); } else { DirectoryInfo di = new DirectoryInfo(path); if (di.Exists) { list_paths.Add(path); } } } foreach (string currPath in list_paths) { // confirm if such directory exists DirectoryInfo di = new DirectoryInfo(currPath.Replace('/', '\\')); if (di.Exists) { // get the following files. List <string> files = FileOperations.I.GetFilesRecursive(currPath, regex, (s) => { ProgressWorker.I.EnQ("Scanning directory " + s); }); files.Reverse(); foreach (string file in files) { if (!IsWhitelisted(file)) { // enqueue file for deletion Worker.I.EnqueTTD(new Model_ThingsToDelete() { FullPathName = file, IsWhitelisted = false, OverWrite = false, WhatKind = THINGS_TO_DELETE.file, command = COMMANDS.delete, search = include_dir ? SEARCH.walk_all : SEARCH.walk_files, path = di.FullName, level = Action.parent_option.level, cleaner_name = Action.parent_option.label }); } } } } }