How can FileInfo.LastWriteTime be earlier than FileInfo.CreationTime?

I debugged some code today and noticed that one of my FileInfo objects had LastWriteTime before CreationTime time. Is this possible / expected?

+6
source share
4 answers

These file properties can be changed to get any value. Therefore, absolutely nothing can stop this from happening.

However, the most likely explanation is that the file was copied from one place to another. The creation time will be the copy time. The modification time will be the time when the original file was last modified, that is, before the copy. Thus, when a file is copied, the modification time is also copied. For this to happen, simply select the file on your computer. Create a copy of it (CTRL + C, CTRL + V) and look at the properties of the copy.

In other words, at the time of creation this is not a contradiction than the time of modification. The creation time is when this file was created. The modification time is when the contents of the file were changed.

+20
source

Make sure that this is possible, just copy the file and go past it in the same folder, you will see that the dates are different: enter image description here

+4
source

Of course it is possible. The time it takes to create and modify the file is just metadata and can be changed by anyone who feels.

+2
source

This method may return an inaccurate value because it uses its own functions whose values ​​cannot be constantly updated by the operating system.

http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.lastwritetime.aspx

+2
source

Source: https://habr.com/ru/post/913909/


All Articles