In Python how do I search for files created in the past 24 hours? [closed]

心不动则不痛 提交于 2019-12-02 14:44:48

问题


I am new to python and I want to find all files in a directory that have been created within the past 24 hours. How do I filter the files that were created in 24 hour window.

This code will be used in Python 2.7 on Windows computer.


回答1:


Get the stat of the file then check if its less then 24 hours... You will need to do loop/recreation...

import os
import time
st = os.stat("test.py")
ctime = st.st_ctime
print time.time() - ctime/3600 // hours
    if mtime<24:
       print mtime


来源:https://stackoverflow.com/questions/33976529/in-python-how-do-i-search-for-files-created-in-the-past-24-hours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!