using System; using System.Collections.Generic; using System.IO; using ln.http.exceptions; namespace ln.build { public static class PathHelper { public static IEnumerable ResolvePattern(string pattern) => ResolvePattern(pattern, Environment.CurrentDirectory); public static IEnumerable ResolvePattern(string pattern, string start) { string[] patternTokens = pattern.Split('/', StringSplitOptions.RemoveEmptyEntries); List matches = new List(); collect(patternTokens, 0, start, matches); return matches; } static void collect(string[] tokens,int depth,string currentPath, List matches) { if (depth < tokens.Length-1) { foreach (string dirname in Directory.GetDirectories(currentPath, tokens[depth])) { collect(tokens, depth + 1, dirname, matches); } } else if (depth == (tokens.Length - 1)) { foreach (string filename in Directory.GetFiles(currentPath, tokens[depth])) { matches.Add(filename); } } else throw new Exception("serious bug"); } } }