Hey,
I'm trying to compare dates, essentially I want to copy all files that have a date modified of 3 days older or less than 3 days old modified. So far i have the following, it did look to be working before, maybe i made some mistake below:
string fileName = "";
string sourceFile = System.IO.Path.Combine(ExpandedSystemRoot, fileName);
string destFile = System.IO.Path.Combine(targetdir, fileName);
string[] files = System.IO.Directory.GetFiles(ExpandedSystemRoot, "*.flog");
DirectoryInfo dirinfo = new DirectoryInfo(ExpandedSystemRoot);
System.IO.FileInfo[] fileinfo = dirinfo.GetFiles("*.flog");
foreach (FileInfo fi in fileinfo)
{
DateTime nowdate = DateTime.Today;
DateTime filedate = fi.LastWriteTime.Date;
TimeSpan comparevalue = nowdate - filedate;
if (comparevalue.Days < 3)
{
foreach (string s in files)
{
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetdir, fileName);
System.IO.File.Copy(s, destFile, true);
sw.WriteLine("Log " + s + " has been copied..");
}
}
}
Thanks
Steve