Re: Search exception filter
Intuitively, it's probably faster to write a loop that looks like:
Code:
For Each directoryPath In Directory.EnumerateDirectories(...)
If IsGood(directoryPath)
Console.WriteLine(myPath)
End If
Next
This only has to go over the list once. If you do it the other way, you have to iterate at least twice: once to build the list, then a second time to remove items you don't want. But it's also trickier, because iterating over a list while you are changing it takes a little more care.
I think your second question is "How do I find folders that match a certain pattern?" That'll depend on the pattern, but a Regex is probably a workable choice here. For example, this function would enumerate and reject the paths that end with "dontuseme":
Code:
Sub PerformEnumeration()
For Each directoryPath In Directory.EnumerateDirectories(...)
If IsGood(directoryPath)
Console.WriteLine(myPath)
End If
Next
End Sub
Function IsGood(ByVal directoryPath as String) As Boolean
Dim badPattern = "\\\d+\\dontuseme\\$"
Return Not System.Text.RegularExpressions.IsMatch(directoryPath, badPattern)
End Function
That regular expression says "Match strings that end with a \ followed by any number of digits, another \, the string "dontuseme", and one more backslash". They are convenient for matching certain strings, but there might be better ways if your pattern is more complex.