How to get file creation & modification date/times in Python?

前端 未结 13 1999
抹茶落季
抹茶落季 2020-11-21 11:44

I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.

13条回答
  •  长发绾君心
    2020-11-21 12:15

    I was able to get creation time on posix by running the system's stat command and parsing the output.

    commands.getoutput('stat FILENAME').split('\"')[7]
    

    Running stat outside of python from Terminal (OS X) returned:

    805306374 3382786932 -rwx------ 1 km staff 0 1098083 "Aug 29 12:02:05 2013" "Aug 29 12:02:05 2013" "Aug 29 12:02:20 2013" "Aug 27 12:35:28 2013" 61440 2150 0 testfile.txt
    

    ... where the fourth datetime is the file creation (rather than ctime change time as other comments noted).

提交回复
热议问题