本文共 461 字,大约阅读时间需要 1 分钟。
查找出含有特定文件并且24小时内有更新的目录:
#!/usr/bin/python
import os
import datetimedir="/root/python"
import datetime
now = datetime.datetime.now()
deltaH = datetime.timedelta(seconds=86400)
for root,dirs,files in os.walk(dir):
for f in files:if f == "aa.txt":j = datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(root,f))if j > (now - deltaH):print os.path.dirname(os.path.join(root,f)) :wq转载于:https://blog.51cto.com/yangzhiming/2125926