您的位置:首页 > 编程语言 > Python开发

使用Python统计垃圾文件

2015-10-04 15:34 676 查看
经常在百度网盘下载文件后会残留一些垃圾文件,如xxx.baiduyun.downloading、xxx.baiduyun.downloading.cfg

通过Python脚本可以很轻松地将这些垃圾文件清除

#coding:utf-8
import os
import re
reg = r'.*downloading'
totalSize = 0
count = 0
path = unicode('C:\Users\\byte\Documents', 'utf8')
for roots, dirs, files in os.walk(path):
for fileName in files:
if re.match(reg, fileName):
filePath = roots+'\\'+fileName
fileSize = round(os.path.getsize(filePath)/1024.0/1024.0, 2)
totalSize = totalSize+fileSize
print ' '+(str(fileSize)+' MB ').ljust(12, '-') , filePath
count = count+1
os.remove(filePath)

print '-'*200
print '\tfile(s): %d\ttotalSize: %f MB' % (count, totalSize)


这些垃圾文件足足占了6G空间!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: