I was trying to make a code where I had to change creation time of a file to creation time of another file (copying creation time from one file to another). I could find some answers about changing creation time on the following links and they work very well as well.
How do I change the file creation date of a Windows file?
Modify file create / access / write timestamp with python under windows
But when I try to put the code mentioned in an executable using pyinstaller it shows the following error:
AttributeError: 'pywintypes.datetime' object has no attribute 'astimezone'
How can I get over this error?
Below is the code which can be used to reproduce the situatuion
import pywintypes, win32file, win32con, ntsecuritycon
import os
def changeFileCTime(fname, createdNewtime):
wintime = pywintypes.Time(int(createdNewtime))
winfile = win32file.CreateFile(fname, ntsecuritycon.FILE_WRITE_ATTRIBUTES, 0, None, win32con.OPEN_EXISTING, 0, None)
win32file.SetFileTime(winfile, wintime, None, None)
winfile.close()
def main():
filename = input("File to copy creation time from: ")
ctime = os.path.getctime(filename)
filename = input("File to set ctime to: ")
changeFileCTime(filename, ctime)
if __name__ == '__main__':
main()
Versions of programs:
- Python - 3.8.2
- Pyinstaller - 4.1
pyinstaller code:
pyinstaller --onefile --console test.py
where test.py is the filename with the above code.