import os
import time
filePath = 'C:\\Users\\Ben\\Downloads'
dir =os.getcwd()
currTime = time.time()
day = (30 * 86400)
executionDate = currTime - day
if(currTime > executionDate):
os.remove(filePath)
else:
print("Nothing older than 30 days in download file.")
我运行这个脚本删除任何文件在我的下载文件夹,这是超过30天。你知道吗
我得到WindowsError: [Error 5]
告诉我访问被拒绝。你知道吗
我试过以管理员的身份运行pyCharm,以用户和管理员的身份从命令行运行。我有管理权,但我似乎无法摆脱这个问题。你知道吗
你有一些错误。我从最上面开始,一路往下。你知道吗
这是死代码,因为您从不引用
dir
。任何人都应该警告你这一点。删除它。你知道吗注意,
executionDate
现在总是比现在早30天。你知道吗什么?为什么我们要测试这个?我们已经知道
executionDate
比现在早了30天!你知道吗你要删除目录?呵呵?你知道吗
我认为,您要做的是检查目录中的每个文件,比较其创建时间戳(或上次修改的时间戳)?我不确定)的值,并删除该文件,如果可能的话。你想要
os.stat
和os.listdir
相关问题 更多 >
编程相关推荐