Python实现删除当前目录下重复文件
用Python实现删除当前目录下重复文件:
import os, sys
d = os.getcwd()
all_filename_list = [i for i in os.listdir('.') if os.path.isfile(i)]
import hashlib
not_duplicate_arr = []
for filename in all_filename_list:
full_filename = d + '/' + filename
with open(full_filename, 'rb') as file:
file_md5=hashlib.md5(file.read()).hexdigest()
if file_md5 not in not_duplicate_arr:
not_duplicate_arr.append(file_md5)
else:
os.remove(full_filename)