From 7ff8e4ae611b7f4fd5a0e4bef0176e3f5ecea5d6 Mon Sep 17 00:00:00 2001 From: zmaster Date: Mon, 29 Jun 2026 11:53:06 +0300 Subject: [PATCH] first commit --- .../getHashes.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Collect a hash of all files in a directory/getHashes.py diff --git a/Collect a hash of all files in a directory/getHashes.py b/Collect a hash of all files in a directory/getHashes.py new file mode 100644 index 0000000..887f588 --- /dev/null +++ b/Collect a hash of all files in a directory/getHashes.py @@ -0,0 +1,30 @@ +import sys +import hashlib +from pathlib import Path + +if len(sys.argv) > 1: + folder_path = Path(sys.argv[1]) +else: + folder_path = Path(".") # Current directory + +print(f"Check directory {folder_path}") +output_file = Path("hashes.txt") + +with open(output_file, "w", encoding="utf-8") as f: + for file in folder_path.rglob("*"): + if file.is_file(): + if file.is_symlink(): + print(f"File is a link - {file}") + f.write(f"File is a link - {file}\n") + else: + hasher = hashlib.md5() + try: + print(f"Getting a hash for a file: {file}") + # Read file in 64KB chunks to protect system memory + with open(file, "rb") as file_bytes: + for chunk in iter(lambda: file_bytes.read(65536), b""): + hasher.update(chunk) + file_hash = hasher.hexdigest() + f.write(f"{file_hash} - {file}\n") + except Exception as e: + f.write(f"ERROR {file} ({e})\n")