Created
January 15, 2026 04:52
-
-
Save GluTbl/3853c0375a8dca038006cb6460583b44 to your computer and use it in GitHub Desktop.
[sha256sum folder] #python
This file contains hidden or 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
| def sha256sum_folder(folder_path, output_file="checksum.sha256sum"): | |
| folder = Path(folder_path) | |
| output_path = folder / output_file | |
| with open(output_path, "wb") as out: | |
| for file in sorted(folder.iterdir()): | |
| # Skip directories and the output file itself | |
| if file.is_file() and file.name != output_file: | |
| sha256 = hashlib.sha256() | |
| with open(file, "rb") as f: | |
| for chunk in iter(lambda: f.read(8192), b""): | |
| sha256.update(chunk) | |
| # Linux sha256sum format: <hash><two spaces><filename> | |
| out.write(f"{sha256.hexdigest()} {file.name}\n".encode("utf-8")) | |
| return output_path | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment