I have this function, that used to read a directory contacting hundreds of thousands of files and get count of files for a specific date. Is there a way to use a search/count pattern based on the supplied date?
This works fine, but it takes too long time. Is there a better to do this?
I'm using VS 2008 (my client m/c. where I cannot upgrade either framework nor the VS)
public static int GetFileCount(DirectoryInfo filePath)
{
int requestCount = 0;
int day = -1;
FileInfo[] files = filePath.GetFiles();
DateTime minDate = DateTime.Today.AddDays(day);
DateTime maxDate = DateTime.Today;
DateTime lastWriteTime = DateTime.MinValue;
foreach (FileInfo file in files)
{
if (file.LastWriteTime < maxDate && file.LastWriteTime > minDate)
{
requestCount++;
//lastWriteTime = file.LastWriteTime;
}
}
return requestCount;
}