问题
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