Skip to content

Instantly share code, notes, and snippets.

@wrenoud
Created November 12, 2018 21:51
Show Gist options
  • Save wrenoud/8dafab15884cc49303d009ce070f35f4 to your computer and use it in GitHub Desktop.
Save wrenoud/8dafab15884cc49303d009ce070f35f4 to your computer and use it in GitHub Desktop.
import os
import hashlib
def getHashes(folder):
hashes = {}
for root, dirs, files in os.walk(folder):
for file in files:
filepath = os.path.join(root,file)
hash_md5 = hashlib.md5()
with open(filepath, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
hashes[hash_md5.hexdigest()] = filepath
return hashes
left = getHashes("/home/pi/Downloads")
right = getHashes("/home/pi/Downloads")
for hsh, filepath in left.items():
if hsh in right:
print("Match:", filepath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment