Reputation: 909
Well, I create numerous files using the FileInfo.Create()
method, then after some time has passed, I look for all files that are created on that date.
oCurrentFile
= new FileInfo(oFileRegion.Directory.FullName + "\\" + _traceFilePrefix
+ sIdentifier + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss.ffff") + _traceFileExt);
FileStream fs = oCurrentFile.Create(); fs.Close();
This worked very well for days! Now recently, I tried to gather all the files that were created yesterday.
IEnumerable<FileInfo> oldFiles =
(from oldFile in oldFiles
where oldFile.CreationTime.DayOfYear == DateTime.Now.Substract(new TimeSpan(1,0,0,0).DayOfYear
orderby oldFile.CreationTime ascending
select oldFile)
When I looked up the number of files using .Count()
the surprise was big: 0.
So I checked why it didn't found any files and noticed, that all my files had the following creation date:
01.01.1601 00:00:00.000
What the heck? What causes such a strange behaviour? And why Windows stopped getting creation dates right out of nowhere?
Upvotes: 1
Views: 263
Reputation: 2796
I had the same behavior for files which FileInfo didn't think existed. Make sure that the file exists, and that it was created BEFORE the FileInfo object. Otherwise, you need to call FileInfo.Refresh() in order for the state data within the FileInfo object to be updated.
Upvotes: 1