How to rename a file and save the creation date in Python

I know that the creation date is not saved in the file system itself, but I encounter a problem when, when used, os.renameit updates the creation date of the files I work with.

Can I rename a file without changing its original creation date?

+3
source share
2 answers

As Tudor said, you should 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))

try it.

+8
source

, os.stat(), som, , newfile os.utime()

+1

All Articles