1def remove_duplicates(dir):
2 unique = []
3 for filename in os.listdir(dir):
4 if os.path.isfile(filename):
5 filehash = md5.md5(file(filename).read()).hexdigest()
6 if filehash not in unique:
7 unique.append(filehash)
8 else:
9 os.remove(filename)
10