Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the file creation date of a Windows file?

How do I change the file creation date of a Windows file from Python?

like image 787
Claudiu Avatar asked Feb 14 '11 19:02

Claudiu


People also ask

Can you change the date created on a file windows?

You can modify the date created by copying a file. The file's created date becomes the modified date and the current date (when the file is copied) becomes the created date. You can copy a file on your PC to check.

How can I change the date modified created of a file?

You can manually change the Last Modified Date/Time for a file using a free software called Attribute Changer from http://www.petges.lu/. You will need to remember the modified date/time of your presentation file, modify the file and then use Attribute Changer to set the modified date/time to the previous one.

How do I change the timestamp on a file in Windows?

If you ever want to quickly update the Modified time stamp of a file to the current day and time, right-click that file, select Properties, select the TimeStamps tab, and then click the Touch button. That will instantly change the Last modified entry to the current day and time.


1 Answers

Yak shaving for the win.

import pywintypes, win32file, win32con def changeFileCreationTime(fname, newtime):     wintime = pywintypes.Time(newtime)     winfile = win32file.CreateFile(         fname, win32con.GENERIC_WRITE,         win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,         None, win32con.OPEN_EXISTING,         win32con.FILE_ATTRIBUTE_NORMAL, None)      win32file.SetFileTime(winfile, wintime, None, None)      winfile.close() 
like image 179
Claudiu Avatar answered Sep 23 '22 11:09

Claudiu