import os
from datetime import datetime, timedelta
path = "."
if __name__ == '__main__':
for root, firs, files in os.walk(path):
for file in files:
if datetime.fromtimestamp(os.path.getctime(file)) < datetime.now() - timedelta(seconds=300):
pass
# os.remove(path + file)
else:
print(" cant not remove name : %s" % file)
标签:__,删除,python,import,datetime,file,path,大于,os
From: https://www.cnblogs.com/guanchaoguo/p/17143331.html