Hi there,
Unfortunately the search options in listing files doesn't have that option, at least to my knowledge. I think you have to write your own method to achieve this. If you are in .net 4.0, you could use
EnumerateDirectories
. Try something like this :
private IEnumerable<DirectoryInfo> EnumerateDirectories(DirectoryInfo dir, string target)
{
foreach (var di in dir.EnumerateDirectories("*",SearchOption.TopDirectoryOnly))
{
if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
if (di.Name.EndsWith(target, StringComparison.OrdinalIgnoreCase))
{
yield return di;
continue;
}
foreach (var subDir in EnumerateDirectories(di, target))
{
yield return subDir;
}
}
}
}
and then :
DirectoryInfo dir = new DirectoryInfo(@"C:\RootDir");
var found = EnumerateDirectories(dir,"target").ToArray();
This way, if you run into a hidden directory, you stop going through sub directories. Be aware that it may to scan 'nested' directories though.
Hope this helps.