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

前端 未结 13 1998
抹茶落季
抹茶落季 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:05

    If following symbolic links is not important, you can also use the os.lstat builtin.

    >>> os.lstat("2048.py")
    posix.stat_result(st_mode=33188, st_ino=4172202, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=2078, st_atime=1423378041, st_mtime=1423377552, st_ctime=1423377553)
    >>> os.lstat("2048.py").st_atime
    1423378041.0
    

提交回复
热议问题