import hashlib
import glob
import os
dir = 'C:/tmp/src/*'
def sha1(fname):
sha1 = hashlib.sha1()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
sha1.update(chunk)
return sha1.hexdigest()
list = []
for v in glob.glob(dir, recursive=True):
hash = sha1(v)
if hash not in list:
list.append(hash)
else:
os.remove(v)