Get file creation time with Python on Mac

前端 未结 3 1584
囚心锁ツ
囚心锁ツ 2020-12-19 01:57

Python\'s os.path.getctime on the Mac (and under Unix in general) does not give the date when a file was created but \"the time of the last change\" (according to the docs a

3条回答
  •  自闭症患者
    2020-12-19 02:04

    By lack of a good utility, I've created crtime.

    pip install crtime
    

    Then you can use it like:

    sudo crtime ./
    

    Would print:

    1552938281  /home/pascal/crtime/.gitignore
    1552938281  /home/pascal/crtime/README.md
    1552938281  /home/pascal/crtime/crtime
    1552938281  /home/pascal/crtime/deploy.py
    1552938281  /home/pascal/crtime/setup.cfg
    1552938281  /home/pascal/crtime/setup.py
    1552938961  /home/pascal/crtime/crtime.egg-info
    1552939447  /home/pascal/crtime/.git
    1552939540  /home/pascal/crtime/build
    1552939540  /home/pascal/crtime/dist
    

    Note that for large directories it will be easily 1000x faster than xstat that is sometimes mentioned, as this creates a temporary file and then executes stat calls for all files at once.

提交回复
热议问题