import os import sys import hashlib try: root = sys.argv[1] except: root = "." hashes = {} for root, dirs, files in os.walk(root): path = root.split('/') for file in files: fpath = os.path.join("".join(path), file) hashes[fpath] = hashlib.md5(open(fpath, 'rb').read()).hexdigest() fnames = sorted(hashes.keys()) dirhash = "" for fname in fnames: dirhash += hashes[fname] print hashlib.md5(dirhash).hexdigest()