public static IEnumerable <string> FindFiles(string pattern) { //TODO //Path.IsPathRooted(pattern); var tokens = PatternUtils.Tokenize(pattern); if (tokens.Length < 2) { return(Enumerable.Empty <string>()); } string ds = Path.DirectorySeparatorChar.ToString(); var first = tokens[0]; if (first.EndsWith(":", StringComparison.Ordinal)) { // if the token is a windows drive, add a backslash to make it an absolute path. first += ds; } else if (pattern.StartsWith(ds, StringComparison.Ordinal)) { // if the token was originally an absolute path (unix) or absolute path // minus the drive letter (windows) add the slash/backslash again. first = ds + first; } return(FindFiles(first, tokens.Skip(1)).ToList()); }
public FileWatcher(string pattern, Action <string> action) { _action = action; //TODO check if rooted _regex = new Regex("^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$", RegexOptions.IgnoreCase | RegexOptions.Singleline); _pattern = pattern; _queue = new Queue <KeyValuePair <string, IEnumerable <string> > >(); var tokens = PatternUtils.Tokenize(pattern); _queue.Enqueue(new KeyValuePair <string, IEnumerable <string> >(tokens[0] + Path.DirectorySeparatorChar, tokens.Skip(1))); CreateWatchers(); }