调用python脚本清理xp系统临时文件

clean_py

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)

Author: robinchenyu

Created: 2014-01-14 浜 13:32

Emacs 24.3.1 (Org mode 8.2.4)

Validate

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值