/// <summary> /// Resolves all file patterns in this file set to absolute paths. /// </summary> /// <returns>A sequence of file items with additional information</returns> public IEnumerable <Item> Resolve() { if (resolved != null) { return(resolved); } resolved = new HashSet <Item>(); foreach (var each in includes) { // replace backward slash to play nicely with Glob var globPattern = each.Pattern.Replace(@"\", "/"); var matches = Glob .GetMatches(globPattern) .Where(file => !excludes.Any(exclusion => exclusion.Match(file))) .Select(each.Create); foreach (var item in matches) { resolved.Add(item); } } foreach (var item in absolutes) { resolved.Add(item); } return(resolved); }
/// <summary> /// Resolves all file patterns in this file set to absolute paths. /// </summary> /// <returns>A sequence of file items with additional information</returns> public IEnumerable <Item> Resolve() { if (resolved != null) { return(resolved); } resolved = new HashSet <Item>(); foreach (var each in includes) { var inclusion = each; var matches = Glob .GetMatches(inclusion.Pattern) .Where(file => !excludes.Any(exclusion => exclusion.Match(file))) .Select(inclusion.Create); foreach (var item in matches) { resolved.Add(item); } } foreach (var item in absolutes) { resolved.Add(item); } return(resolved); }
private static List <string> GetMatches(string pattern) { var globTestDir = GetGlobTestDir(); globTestDir = globTestDir.Replace("\\", "/") + "/"; var matches = Glob.GetMatches(string.Format("{0}" + pattern, globTestDir)).ToList(); return(matches); }
protected override string BuildArgs() { var runDir = Path.GetDirectoryName(configFile); var configText = File.ReadAllText(configFile); var config = JsonConvert.DeserializeObject <JasmineConfig>(configText); sourceFiles = config.src_files.SelectMany(f => Glob.GetMatches(CanonicalizePath(Path.Combine(runDir, config.src_dir, f)))).ToArray(); testFiles = config.spec_files.SelectMany(f => Glob.GetMatches(CanonicalizePath(Path.Combine(runDir, config.spec_dir, f)))).ToArray(); return(base.BuildArgs()); }
public void EnqueueFiles(string regex = "") { IEnumerable <string> path_and_file = Glob.GetMatches(Action.path.Replace('\\', '/'), Glob.Constants.IgnoreCase); foreach (string file in path_and_file) { Worker.I.EnqueTTD(new Model_ThingsToDelete() { FullPathName = file.Replace('/', '\\'), IsWhitelisted = false, OverWrite = false, WhatKind = THINGS_TO_DELETE.file, command = COMMANDS.sqlite_vacuum, search = SEARCH.file, level = Action.parent_option.level, cleaner_name = Action.parent_option.label }); } }
static void Main(string[] args) { string input; if (args.Length == 0) { input = Console.ReadLine(); } else { input = args[0]; } var results = Glob.GetMatches(input, 0); foreach (var result in results) { Console.WriteLine(result); } }
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 }); } } } }
public void Search_Glob(string regex = null) { List <string> list_paths = new List <string>(); IEnumerable <string> path_and_file = Glob.GetMatches(Action.path.Replace('\\', '/'), 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(path_and_file); 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 = SEARCH.glob, path = di.FullName, level = Action.parent_option.level, cleaner_name = Action.parent_option.label }); } } } else { // then it must be a file FileInfo fi = new FileInfo(currPath); 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 = fi.FullName, IsWhitelisted = false, OverWrite = false, WhatKind = THINGS_TO_DELETE.file, command = COMMANDS.delete, search = SEARCH.glob, path = fi.Directory.FullName, 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 }); } } } } }