Ado*_*obe 12 python python-2.7
可能重复:
python:哪个文件更新,多少时间
在python中 - 如何检查 - 文件是否比其他文件更新?
编辑:
有创建时间和修改时间.
问题应该明确说明所需的财产.
os.stat(FILE).st_mtime
os.path.getmtime(FILE)
os.path.getctime(FILE)并且os.stat(FILE).st_ctime不会在类Unix操作系统上创建创建时间.通过root 链接有关于如何在类Unix的盒子上找出创建时间的解决方案.
Tri*_*Nhu 10
import os
f1 = os.path.getmtime('file1')
f2 = os.path.getmtime('file2')
if f1 > f2:
Run Code Online (Sandbox Code Playgroud)
检查修改时间可能是一个解决方案
你也可以使用os.path.getctime.这个例子将返回True如果file1之前创建file2和False其他.
import os.path
os.path.getctime('file1') < os.path.getctime('file2')
Run Code Online (Sandbox Code Playgroud)
编辑:请注意,您的问题没有跨平台解决方案 - 在Unix中的ctime()意味着上次更改时间,而不是创建时间.使用os.stat(文件).st_ctime时也是如此.
这似乎是可以在unix机器上运行的东西.
| 归档时间: |
|
| 查看次数: |
7069 次 |
| 最近记录: |