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 = "G:lizhi_music"
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)
print("文件:%s已删除"%file)