3

I'm using a file modified date as a base for file names in via C#. My question is what can make the modified date to change? I actually thought the modified date was the created date first. But the created date is changing when I move the file from USB to harddrive. So I had to use the modified date which has the correct, untoched date.

As I thought when the file was moved the modified date was changed but its actually the created date that is changed in Windows 7 at least.

Is there any use case that may change the date of the file (except unpacking it from a zipped file) surprisingly? Like maybe from DVD to harddrive or something like that?

Best regards Mr Rob

4
  • When you open the file with write access and save it back or when you just started to write the file.
    – Ian
    Mar 9, 2016 at 14:46
  • 2
    you do realize that when "moving" files between file systems, a move is a copy+delete? create new file, delete old one. hence you get a new create date AND a new modified date. moving WITHIN a filesystem is simply updating a pointer somewhere to tell the OS/filesystem that the file is in a new location
    – Marc B
    Mar 9, 2016 at 14:47
  • Code. Literally, any other piece of code may choose to change timestamps on files. Mar 9, 2016 at 14:54
  • @MarcB: usually, the creation date changes but the modification date does not, because CopyFile() copies the modification date from the original to the destination. Mar 9, 2016 at 22:59
9

File properties with regards to the date and time stamps

  • If you copy a file from C:\fat16 to C:\fat16\sub, it keeps the same modified date and time but it changes the created date and time to the current date and time.
  • If you move a file from C:\fat16 to C:\fat16sub, it keeps the same modified date and time and keeps the same created date and time.
  • If you copy a file from C:\fat16 to D:\NTFS, it keeps the same modified date and time but changes the created date and time to the current date and time.
  • If you move a file from C:\fat16 to D:\NTFS, it keeps the same modified date and time and keeps the same created date and time.
  • If you copy a file from D:\NTFS to D:\NTFS\SUB, it keeps the same modified date and time but changes the created date and time to the current date and time.
  • If you move a file from D:\NTFS to D:\NTFS\SUB, it keeps the same modified date and time and keeps the same created date and time.
  • In all examples, the modified date and time of a file does not change unless a property of the file has changed. The created date and time of the file changes depending on whether the file was copied or moved.

For more information see KB299648.

2
  • last access stamp however changes on both move and copy
    – ns94
    Aug 22, 2020 at 15:04
  • Is there a way to obtain the "original created date/time" from the non-copied file or is this information discarded when copying a file?
    – D.R.
    Oct 5, 2020 at 17:21
0

I believe that the modification date would be changed when the file contents change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.