In Python how do I search for files created in the

2020-05-07 06:40发布

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条回答
贼婆χ
2楼-- · 2020-05-07 07:18

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
查看更多
登录 后发表回答