import os
import zlib
import time
import re
#递归文件夹
def recursionFolder(path):
filename_regex = re.compile(r'.*\(\d+\)\..*')
crcList=list()
for root,dirs,files in os.walk(path):
for file in files:
print(os.path.join(root,file))
temp = filename_regex.search(file)
if temp != None:
os.remove(os.path.join(root,file))
if os.path.exists((os.path.join(root,file))):
fileCRC=crc32(os.path.join(root,file))
if fileCRC in crcList:
os.remove(os.path.join(root,file))
else:
crcList.append(fileCRC)
#获取文件crc值
def crc32(file_path):
with open(file_path, 'rb') as fh:
hash = 0
while True:
s = fh.read(65536)
if not s:
break
hash = zlib.crc32(s, hash)
return "%08X" % (hash & 0xFFFFFFFF)
recursionFolder("./") #此处目录替换成自己电脑微信目录
发表评论: