I know that the creation date isn't stored in the filesystem itself, but I'm encountering the problem that when I use os.rename
, it's updating the creation date of the files I'm working with.
Is it possible to rename a file without changing its original creation date?
As said by Tudor you can use os.stat() and os.utime().
stat = os.stat(myfile)
# your code - rename access and modify your file
os.utime(my_new_file, (stat.st_atime, stat.st_mtime))
You can read the timestamp before modifying it with os.stat()
, keep it in som variable, rename the file, then change newfile's timestamp to the held value with os.utime()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With