Python删除windows 垃圾文件

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用

[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'))


标签: 代码

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:Python获取Linux系统内存情况

下一篇:计算一个点是否在多边形里 Python 版