Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Original creation date of a copied file

Tags:

python

I have a copy of a previously generated file and want to detect the creation date of that original file.

I can use the following code to get the creation date of that copy, but not of the original file:

import os.path, time
print("last modified: %s" % time.ctime(os.path.getmtime(file)))
print("created: %s" % time.ctime(os.path.getctime(file)))

Source: http://www.aitek.ch/how-to-get-file-creation-modification-date-times-in-python/

But this will only retrive the creation date of the copy, not the creation date of the original file. I have read that if you copy a file on windows the old creation date will be the new modified date and the date of the copy will be the new creation date. I have also read that in the metda date there might be a real original file creation date but it seems I am unable to find it.

like image 235
Andreas Avatar asked Sep 01 '25 10:09

Andreas


2 Answers

This is really a Windows thing. Windows does not preserve the creation_time in the copied file of the original file.

The modification time is copied. The creation time is always the current system time.

I think the best you can do is retrieve the original (if possible at all) and take the creation time from the original file.

There are also some tricks you may use, but it really depends on your situation whether they meet your needs: https://superuser.com/questions/146125/how-to-preserve-file-attributes-when-one-copies-files-in-windows

like image 137
Ronald Avatar answered Sep 09 '25 09:09

Ronald


This is an operating system dependant issue. It all depends on the fact that while copying the files we ensure the creation date is preserved. On Windows, pressing shift while copying preserves the creation date. Failing that, the file system will not retain the original creation date. You may have to ressort to the meta data stored in the file itself which is file format dependant.

like image 29
Tarik Avatar answered Sep 09 '25 10:09

Tarik