clean_py
Table of Contents
1 清理XP下临时文件脚本
调用Python程序清理文件夹下的临时文件还是很方便的。
import os profile_dir = os.getenv("USERPROFILE") template_dirs = { 'chrome': "Local Settings/Application Data/Google/Chrome/User Data/Default/Cache", 'IE': "Local Settings/Temporary Internet Files", 'firefox': "Local Settings/Application Data/Mozilla/Firefox/Profiles/0uhragjh.default/Cache", 'Temp': "Local Settings/Temp", 'history': "Local Settings/History", 'recent': "Recent", 'Temp2': "C:/WINDOWS/Temp", 'pack': "C:/WINDOWS/ServicePackFiles", } for name, dir1 in template_dirs.items(): count = 0 # print "remove template files for %s" % name for root, dirs, files in os.walk(os.path.join(profile_dir, dir1)): # print "in dir %s %d %d" % (root, len(dirs), len(files)) for f in files: try: os.remove(os.path.join(root, f)) count += 1 except Exception as e: print "remove file %s failed" % os.path.join(root,f) for d in dirs: try: os.rmdir(os.path.join(root, d)) count += 1 except Exception as e: print "remove dir %s failed" % os.path.join(root, d) print "remove %d files in %s %s" % (count, name, dir1)