Get file creation time with Python on Mac

前端 未结 3 1590
囚心锁ツ
囚心锁ツ 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:20

    ctime differs on the platform: On some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time. That's because Unices usually don't preserve the "original" creation time.

    That said you can access all information that the OS provides with the stat module.

    The stat module defines constants and functions for interpreting the results of os.stat(), os.fstat() and os.lstat() (if they exist). For complete details about the stat, fstat and lstat calls, consult the documentation for your system.

    stat.ST_CTIME
    The “ctime” as reported by the operating system. On some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time (see platform documentation for details).

提交回复
热议问题