Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

file

time

I was debugging some code today and noticed one of my FileInfo objects had its LastWriteTime earlier than its CreationTime time. Is this possible/expected?

like image 386
probably at the beach Avatar asked Apr 23 '12 09:04

probably at the beach


3 Answers

These properties of the file can be modified to take any value. So there's absolutely nothing to stop this happening.

That said, the most likely explanation is that the file was copied from one place to another. The creation time will be the time the copy took place. The modification time will be the time the source file was last modified, i.e. before the copy. So, when the file is copied, the modification time is also copied. To see this happen, simply pick a file on your machine. Create a copy of it (CTRL+C, CTRL+V) and look at the properties of the copy.

In other words, it is actually not a contradiction for the creation time to be later than the modification time. The creation time is when this file object was created. The modification time is when the file contents were modified.

like image 81
David Heffernan Avatar answered Nov 15 '22 06:11

David Heffernan


Sure its possible, just copy some file and past it in the same folder, you will see the dates are different: enter image description here

like image 39
Habib Avatar answered Nov 15 '22 08:11

Habib


Of course it's possible. Creation and modification time of a file are just metadata and can be changed by anyone who feels like it.

like image 2
Joey Avatar answered Nov 15 '22 07:11

Joey