import os
import hashlib
def get_md5(file):
file = open(file, 'rb')
md5 = hashlib.md5(file.read())
file.close()
md5_values = md5.hexdigest()
return md5_values
file_path = "E:\\yuan2\\"
os.chdir(file_path)
file_list = os.listdir(file_path)
md5_list = []
for file in file_list:
md5 = get_md5(file)
if md5 not in md5_list:
md5_list.append(md5)
else:
os.remove(file)