python - 检查文件是否比其他文件更新?

标签 python python-2.7

<分区>

Possible Duplicate:
python: which file is newer & by how much time

在 python 中——我如何检查——文件是否比其他文件更新?

编辑:

有创建时间和修改时间。

问题应明确说明所需的属性。

修改

  • os.stat(FILE).st_mtime

  • os.path.getmtime(FILE)

创作

os.path.getctime(FILE)os.stat(FILE).st_ctime 在类 Unix 操作系统上不提供创建时间。 Link通过 root有关于如何在类 Unix 机器上找出创建时间的解决方案。

最佳答案

您也可以使用 os.path.getctime。如果 file1file2 之前创建,此示例将返回 True,否则返回 False

import os.path
os.path.getctime('file1') < os.path.getctime('file2')

编辑:请注意 there is no cross platform solution to your question -- Unix 中的 ctime() 表示最后更改时间,而不是创建时间。 The same applies when using os.stat(file).st_ctime.

Here似乎可以在 unix 机器上运行。

关于python - 检查文件是否比其他文件更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12817041/

相关文章:

python - 为什么在 logging.info 中显示名称错误?

python - 为现有的 Plone 3.3.4 安装向 Python 添加 SSL 支持

c++ - 如何编写一个程序,可以像 Ubuntu 中的命令一样添加信息(例如 : program -u "Hello World")

python - ctypes 中的 const void* 指针

python - Django python 中的 mysql 'LIKE'

python - fstat() 是安全的(沙盒)操作吗?

Python 类不适用于排序函数

python - += : 'NoneType' and 'list' 不受支持的操作数类型

python - 在用 numpy 绘图时使用修改后的 arctan2 的错误

python - 在 Python 中反转堆栈