I'm ultimately trying to compare the MD5 hashes for files in two disparate directory trees to see if files are missing from one directory or the other.
More broadly, I'm pushing photos from my DSLR camera to Google Drive, and need to know which files need to be synced up. Pictures from my phone are automatically being synced with Google Drive, and I'd also like to detect which ones I need to sync down. I have separate scripts for getting the MD5 hashes from Google Drive and for comparing the MD5 hashes to see which files need to be synced, up or down.
#!/usr/bin/python import os import sys import hashlib import csv src_dir = '/Volumes/Archive/Pictures' with open('checksums_archive.tsv', 'wb') as fout: writer = csv.writer(fout, delimiter='\t', quotechar='\"', quoting=csv.QUOTE_MINIMAL) for root, subdirs, files in os.walk(src_dir): for file in files: file_path = os.path.join(root, file) checksum = hashlib.md5(open(file_path, 'rb').read()).hexdigest() writer.writerow([root, file, checksum])