import glob
import hashlib
from time import perf_counter
def get_file_md5(file):
md5 = hashlib.md5()
with open(file,'rb') as fp:
sc_read = fp.read()
md5.update(sc_read)
return md5.hexdigest()
if __name__ == '__main__':
all_md5 = dict()
file_dir = r'E:\images\*.png'
start = perf_counter()
for file in glob.iglob(file_dir):
md5 = get_file_md5(file)
if md5 in all_md5:
all_md5[md5] += '\n' + file
else:
all_md5[md5] = '\n' * 2 + file
end = perf_counter()
print (f"耗时:{end-start}")
print (len(all_md5))
欢迎关注本人微信公众号,会分享更多的干货: