import hashlib import os def calculate_md5(file_path): """Calculate the MD5 checksum of a file.""" hash_md5 = hashlib.md5() with open(file_path, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk) return hash_md5.hexdigest() def check_checksums(file_with_checksums): """Check if the checksums of the files agree with the ones stored in the file.""" with open(file_with_checksums, 'r') as f: for line in f: md5_sum, file_path = line.strip().split(maxsplit=1) if os.path.isfile(file_path): calculated_md5 = calculate_md5(file_path) if calculated_md5 == md5_sum: print(f"Checksum matches for {file_path}") else: print(f"Checksum does NOT match for {file_path}: expected {md5_sum}, got {calculated_md5}") else: print(f"File does not exist: {file_path}") # Replace 'checksums.txt' with the path to your text file check_checksums('checksums.txt')