I have a huge directory I need retrieve files from including subdirectories.
I have files that are folders contain various files but I am only interested in specific proprietary files named with an extension with a length of 7 digits.
For example, I have folder that contains the following files:
abc.txt def.txt GIWFJ1XA.0201000 GIWFJ1UC.0501000 NOOBO0XA.0100100 summary.pdf someinfo.zip T7F4JUXA.0300600 vxy98796.csv YJHLPLBO.0302300 YJHLPLUC.0302800 I have tried the following:
var fileList = Directory.GetFiles(someDir, "*.???????", SearchOption.AllDirectories) and also
string searchSting = string.Empty; for (int j = 0; j < 9999999; j++) { searchSting += string.Format(", *.{0} ", j.ToString("0000000")); } var fileList2 = Directory.GetFiles(someDir, searchSting, SearchOption.AllDirectories); which errors because the string is too long obviously.
I want to only return the files with the specified length of the extension, in this case, 7 digits to avoid having to loop over the thousands I would have to process.
I have considered creating a variable string for the search criteria that would contain all 99,999,999 possible digits but d
How can I accomplish this?
Regex r = new Regex(@"\.\d{7}$");andGetFiles(...).Where(r.IsMatch)- I'd use EnumerateFiles but this Regex is "ends with a dot and 7 digits" which is a compact alternative too