1 import os
2 import time
3 root_dir = r'E:\I-SEARCH\考核追踪交付文档'
4 def clear_file(root_dir):
5 for root, dir, names in os.walk(root_dir):
6 print(root, dir, names)
7 for name in names:
8 filename = os.path.join(root, name)
9 print(filename)
10 #文件创建时间戳
11 ct = os.stat(filename).st_ctime
12 #当前时间戳
13 nt = time.time()
14 #文件创建时间
15 tt = nt - ct
16 #返回 分 秒
17 m, s = divmod(tt, 60)
18 #小时,分钟
19 h, m = divmod(m, 60)
20 #天,小时
21 d, h = divmod(h, 24)
22 if d >= 1:
23 print("文件超过1天,执行清理")
24 clear_file(root_dir)