Hello All,
I'm currently having an issue when evaluating FileInfo.LastWriteTime between two files. Basically, the two files in question have the IDENTICAL LastWriteTime values, however the following code evaluates to false:
FileInfo f1 = new FileInfo("C:\\FileTest2\\IUS_GEN.MNV"); FileInfo f2 = new FileInfo("C:\\FileTest2\\SubFolder\\IUS_GEN.MNV");f1.LastWriteTime == f2.LastWriteTime //this evaluates to false
Strange thing is, if I convert LastWriteTime to string, it evaluates correctly, as in:
f1.LastWriteTime.ToString() == f2.LastWriteTime.ToString() //this evaluates to true!
Both files have the LastWriteTime.ToString() value of 9/01/2006 8:25:47 AM
What's going on It seems to evaluate correctly as the native DateTime type for some files, but not all. Is precision lost when converting to string
Cheers
Rob

FileInfo.LastWriteTime issue: does not correctly evaluate
Shawn Burke
> Is precision lost when converting to string
The string you are generating has the time to the nearest second: DateTime is more accurate so yes, precision is lost.
To understand what's happening, you could try formatting with fractions of seconds (e.g. LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff").
Solve-IT