Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code> /// &lt;summary&gt; /// return a list of files that matches some wildcard pattern, e.g. /// C:\p4\software\dotnet\tools\*\*.sln to get all tool solution files /// &lt;/summary&gt; /// &lt;param name="glob"&gt;pattern to match&lt;/param&gt; /// &lt;returns&gt;all matching paths&lt;/returns&gt; public static IEnumerable&lt;string&gt; Glob(string glob) { foreach (string path in Glob(PathHead(glob) + DirSep, PathTail(glob))) yield return path; } /// &lt;summary&gt; /// uses 'head' and 'tail' -- 'head' has already been pattern-expanded /// and 'tail' has not. /// &lt;/summary&gt; /// &lt;param name="head"&gt;wildcard-expanded&lt;/param&gt; /// &lt;param name="tail"&gt;not yet wildcard-expanded&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public static IEnumerable&lt;string&gt; Glob(string head, string tail) { if (PathTail(tail) == tail) foreach (string path in Directory.GetFiles(head, tail).OrderBy(s =&gt; s)) yield return path; else foreach (string dir in Directory.GetDirectories(head, PathHead(tail)).OrderBy(s =&gt; s)) foreach (string path in Glob(Path.Combine(head, dir), PathTail(tail))) yield return path; } /// &lt;summary&gt; /// shortcut /// &lt;/summary&gt; static char DirSep = Path.DirectorySeparatorChar; /// &lt;summary&gt; /// return the first element of a file path /// &lt;/summary&gt; /// &lt;param name="path"&gt;file path&lt;/param&gt; /// &lt;returns&gt;first logical unit&lt;/returns&gt; static string PathHead(string path) { // handle case of \\share\vol\foo\bar -- return \\share\vol as 'head' // because the dir stuff won't let you interrogate a server for its share list // FIXME check behavior on Linux to see if this blows up -- I don't think so if (path.StartsWith("" + DirSep + DirSep)) return path.Substring(0, 2) + path.Substring(2).Split(DirSep)[0] + DirSep + path.Substring(2).Split(DirSep)[1]; return path.Split(DirSep)[0]; } /// &lt;summary&gt; /// return everything but the first element of a file path /// e.g. PathTail("C:\TEMP\foo.txt") = "TEMP\foo.txt" /// &lt;/summary&gt; /// &lt;param name="path"&gt;file path&lt;/param&gt; /// &lt;returns&gt;all but the first logical unit&lt;/returns&gt; static string PathTail(string path) { if (!path.Contains(DirSep)) return path; return path.Substring(1 + PathHead(path).Length); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload