Skip to content

Instantly share code, notes, and snippets.

@GluTbl
Created January 15, 2026 04:52
Show Gist options
  • Select an option

  • Save GluTbl/3853c0375a8dca038006cb6460583b44 to your computer and use it in GitHub Desktop.

Select an option

Save GluTbl/3853c0375a8dca038006cb6460583b44 to your computer and use it in GitHub Desktop.
[sha256sum folder] #python
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