I'm trying to find some directories on a network drive.
I use Directory.EnumerateDirectories for this. The problem is that it takes very long because there are many subdirectories.
Is there a way to make the function stop searching further down into subdirectories if a match was found and carry on with the next directory on same level?
static readonly Regex RegexValidDir = new ("[0-9]{4,}\\.[0-9]+$");
var dirs = Directory.EnumerateDirectories(startDir, "*.*", SearchOption.AllDirectories)
.Where(x => RegexValidDir.IsMatch(x));
The directory structure looks like that
a\b\20220902.1\c\d\
a\b\20220902.2\c\d\e
a\b\x\20220902.3\
a\b\x\20221004.1\c\
a\b\x\20221004.2\c\
a\b\x\20221004.3\d\e\f\
...
a\v\w\x\20221104.1\c\d
a\v\w\x\20221105.1\c\d
a\v\w\x\20221106.1\c\d
a\v\w\x\20221106.2\c\d
a\v\w\x\20221106.3\c\d
a\v\w\x\20221106.4\
I'm interested in the directories with a date in the name only and want to stop searchin further down into the subdirectories of a matching dir.
Another thing is I don't know if the search pattern I'm supplying (.) is correct for my usage szenario.
The directories are found relatively quickly, but it then takes another 11 minutes to complete the search function