Using C# (.NET), how can I search a file system given a directory search mask like this: (?)
\\\\server\\Scanner\\images\\*Images\\*\\*_*
For e
public static IEnumerable GetImages()
{
//For each "*Image" directory
foreach (var jobFolder in Directory.EnumerateDirectories(@"\\server\Scanner\images", "*Images"))
{
//For each first level subdirectory
foreach (var jobSubFolder in Directory.EnumerateDirectories(jobFolder))
{
//Enumerate each file containing a '_'
foreach (var filePath in Directory.EnumerateFiles(jobSubFolder, "*_*", SearchOption.TopDirectoryOnly))
{
yield return filePath;
}
}
}
}
Only the files from the first level subdirectories of each "*Image" directory are enumerated.
Finally you can use it with:
foreach (var path in GetImages())
{
Console.WriteLine(path);
}