I have some files with this pattern:
PrefixyyyyMMddHHmmss.txt
That Prefix is always the same.
For example :
Prefix20120830115800.txt
Prefix20120829114200.txt
Prefix20120829134621.txt
I want to write a function to get one day and range and returns all files that their names are in input range from that day:
ReadFiles(string filesLocation, DateTime fromDate, int range)
Now I use this approach:
for (int i = 0; i <= range; i++)
{
SearchFolderForFiles(location, fromDate.AddDays(i));
}
SearchFolderForFiles(//params)
{
//…
string searchTemplate = string.Format("Prefix{0:yyyyMMdd}*.txt", date);
DirectoryInfo di = new DirectoryInfo(location);
FileInfo[] myFiles = di.GetFiles(searchTemplate);
//…
}
But I think it should be better way(specially we have range not separated days)
Thanks
You could do it with linq.
Horrible example, but you can see what i’m getting at 🙂