Created
February 28, 2025 09:24
-
-
Save Svtter/74802b6fdc14d605ab2b09580a0b1578 to your computer and use it in GitHub Desktop.
compute sha256sum of files under folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Tools to compute sha256 of files and find duplicate files""" | |
import hashlib | |
import os | |
f = open("sha256.txt", "w") | |
def compute_sha256(file): | |
with open(file, "rb") as f: | |
return hashlib.sha256(f.read()).hexdigest() | |
dicts = {} | |
for root, dirs, files in os.walk("."): | |
for file in files: | |
# compute sha256 | |
sha256result = compute_sha256(os.path.join(root, file)) | |
if sha256result in dicts.keys(): | |
dicts[sha256result].append(os.path.join(root, file)) | |
else: | |
dicts[sha256result] = [os.path.join(root, file)] | |
for sha256result, files in dicts.items(): | |
if len(files) > 1: | |
print(f"{sha256result}\t{files}") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment