#! /usr/bin/python3 import sys, hashlib, os call_path = sys.argv[1] files = [] # (hash, path) def parse(path): global files for f in os.listdir(path): fpath = os.path.join(path, f) if f.startswith('.') or f.startswith('~'): continue elif os.path.islink(fpath): continue elif os.path.isdir(fpath): parse(fpath) else: with open(fpath, mode='rb') as file: hasher = hashlib.sha512() while True: buf = file.read(10000) if not buf: break hasher.update(buf) files.append((hasher.hexdigest(), os.path.relpath(fpath, call_path))) parse(call_path) files.sort(key=lambda t: t[0]) # sort by hash length = len(files) i = 0 while i < length: hash = files[i][0] j = i + 1 if j >= length: break while files[j][0] == hash: j = j + 1 if i + 1 < j: print( ':'.join(t[1] for t in files[i:j]) ) i = j
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question