43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using ln.http.exceptions;
|
|
|
|
namespace ln.build
|
|
{
|
|
public static class PathHelper
|
|
{
|
|
|
|
public static IEnumerable<string> ResolvePattern(string pattern) => ResolvePattern(pattern, Environment.CurrentDirectory);
|
|
public static IEnumerable<string> ResolvePattern(string pattern, string start)
|
|
{
|
|
string[] patternTokens = pattern.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
|
List<string> matches = new List<string>();
|
|
collect(patternTokens, 0, start, matches);
|
|
return matches;
|
|
}
|
|
|
|
static void collect(string[] tokens,int depth,string currentPath, List<string> 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");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |