Reputation: 2783
I have a folder with files coming in as
fileName(prefix) + " " + todayDate.ToString("yyyyMMdd") + ".csv";
For simple file my regex was FilePrefix + @"(.*)\.csv"
How to have a search pattern to get file for only today's date ?
Upvotes: 0
Views: 118
Reputation: 28097
Just do something like this
List<string> fileNames = // wherever you're getting these
var ending = DateTime.Now.ToString("yyyyMMdd") + ".csv";
var filteredFileNames = fileNames.Where(x => x.EndsWith(ending));
Upvotes: 0
Reputation: 6850
It sounds like if you're just searching for today's date, then you should already know exactly what file name you're looking for. So there's no need for a regex - just look for files where
var expectedName = FilePrefix + " " + DateTime.Now.ToString("yyyyMMdd") + ".csv";
String.Compare(fileName, expectedName, StringComparison.OrdinalIgnoreCase) == 0
Upvotes: 3