Reputation: 207
I am having some issues with the following code:
string today = DateTime.Now.ToShortDateString();
DirectoryInfo di = new DirectoryInfo(mySettings._TempDataStoragePath);
FileInfo[] files = di.GetFiles();
foreach (FileInfo f in files)
{
string fileDate = f.CreationTime.ToShortDateString();
if (fileDate.Equals(today))
{
...
}
}
The problem that I am having is that f.CreationTime.ToShortDateString();
is returning today's date and not the actual creation date of the file.
I need to be able to inspect the real creation time.
I suspect DirectoryInfo is returning temp copies and not a reference to the real thing.
How do I obtain the real creation time?
Upvotes: 1
Views: 913
Reputation: 2306
You may be running into an issue called the file tunneling in the OS. The CreationFile
property is indeed the creation file of the actual file and not a temp. However, the date returned may not be accurate as this information is cached in the OS due to the fact that applications usually delete and add the same file instead of changing it.
Call Refresh
on the FileInfo
before getting the creation time. That may help.
Upvotes: 4