# -*- coding: utf-8 -*- import datetime import os # 输入目录 e:\tmp path = input("输入要清理的目录:\n"); # 开始计时 print("开始计时:",datetime.datetime.now().strftime('%H:%M:%S')); # 先遍历匹配查找再循环删除 if(os.path.exists(path)): print("正在删除"); for parent,dirnames,filenames in os.walk(path): for filename in filenames: targetFile = os.path.join(parent,filename) if (os.path.isfile(targetFile) and "cachegrind.out" in targetFile): os.remove(targetFile)
else:
print("该目录不存在!"); # 计时结束 print("结束计时:",datetime.datetime.now().strftime('%H:%M:%S'));
运行效果图:
您可能感兴趣的文章: