Here is example I done to search for files by its filename coded date.
Code:
System.Collections.ArrayList allMatches = new System.Collections.ArrayList();
string[] files = System.IO.Directory.GetFiles(".", "*.log");
// gets fullpath or relative path files
foreach (string fileFullName in files)
{
// get only RRRRMMDD from filename
string fileName = fileFullName.Substring(fileFullName.LastIndexOf('\\') +1,8); // I'm trying to make // only other way and I got some spaces here
int year =Convert.ToInt32(fileName.Substring(0, 4));
int month = Convert.ToInt32(fileName.Substring(4, 2)); // if you read us time switch month for days
int day = Convert.ToInt32(fileName.Substring(6, 2));
DateTime fileDT = new DateTime(year, month,day);
TimeSpan searchMargin = new TimeSpan(7, 0, 0, 0);
TimeSpan fileAge = DateTime.Now - fileDT;
if (fileAge < searchMargin)
{
allMatches.Add(fileFullName);
}
}
cheers
AkipNG
Leave a comment: