Python刪除windows 垃圾文件

LasonyaHart 8年前發布 | 858 次閱讀 Python

[Python]代碼    

#coding:utf-8
import os
#from glob import glob

if os.name == 'nt':
    if 'HOMEPATH' in os.environ:
        home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH']
    else:
        home = os.environ['HOMEPATH']

workpath = os.path.join(home, 'Local Settings')
#?????????
#???????????????try??????????????????????????
def delfile(path):
    for file in os.listdir(path):
        if os.path.isfile(os.path.join(path, file)):
            try:
                print "\n???????????? %s" % (os.path.join(path, file))
                os.remove(os.path.join(path, file))
            except:
                pass
        elif os.path.isdir(os.path.join(path, file)):
            delfile(os.path.join(path, file))
        else:
            pass
#delfile(os.path.join(workpath, 'Temp'))
#delfile(os.path.join(workpath, 'Temporary Internet Files'))
#??????????????????????У?????????????????
def deldir(pa):
    for i in os.listdir(pa):
        if os.path.isdir(os.path.join(pa, i)):
            if len(os.listdir(os.path.join(pa, i))) > 0:
                deldir(os.path.join(pa, i))
                try:
                    os.rmdir(os.path.join(pa, i))
                except:
                    pass
            else:
                try:
                    print "\n???????? %s" % (os.path.join(pa, i))
                    os.rmdir(os.path.join(pa, i))
                except:
                    pass

#deldir(os.path.join(workpath, 'Temp'))
#deldir(os.path.join(workpath, 'Temporary Internet Files'))
print """
     ??????????????????????????
     """
raw_input("????????????")

def md(str):
    import md5
    a = md5.new
    m.update(str)
    return m.hexdigest().lower()

mm = md("jalfIau4hwuXie7")
print mm

print md("%s%s%s"%(mm,"ingrealw-2332682",'123456'))


 本文由用戶 LasonyaHart 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!