I have a folder with two files:
Additionally, a third-party app handles the files as follows:
folderPath
and a searchPattern
out of a databaseDirectory.GetFiles(folderPath, searchPattern)
, processing whatever files match the filter in bulk, then moving the files to an archive folder.It turns out that I have to move my two files into different archive folders, so I need to handle them separately by providing different searchPatterns to select them individually. Please note that I can't modify the third-party app, but I can modify the searchPattern and file destinations in my database.
What searchPattern
will allow me to select Awesome.File.20091031_123002.txt
without including Awesome.File.Summary.20091031_123152.txt
?
If your were going to use LINQ then...
var regexTest = new Func<string, bool>(i => Regex.IsMatch(i, @"Awesome.File.(Summary)?.[\d]+_[\d]+.txt", RegexOptions.Compiled | RegexOptions.IgnoreCase));
var files = Directory.GetFiles(@"c:\path\to\folder").Where(regexTest);
Awesome.File.????????_??????.txt
The question mark (?) acts as a single character place holder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With