PRINT_FOLDER_CHECKSUMS


PRINT_FOLDER_CHECKSUMS


The Python program featured in this tutorial traverses every file inside of a folder, X, (including files which are located inside of each of X’s sub-folders (at all directory depths)) and prints the name of that file and the SHA-256 checksum value of that file. The purpose of recording the checksum value of a particular file, Y, is to determine whether or not a particular copy of Y verbatim matches each bit of Y. A copy of Y is essentially the same permutation of bits as Y if both of those files yeild the same SHA-256 checksum value.

karbytes used the aforementioned Python program to generate the plain-text file named karbytes2025_22_checksums.txt (which lists every zip file checksum (immutably as of 31_DECEMBER_2025 at 11:59PM Pacific Standard Time) of the entire collection of zip files enumerated on the web page at the following Uniform Resource Locator):

https://karbytesforlifeblog.wordpress.com/mdisc_karbytes2025_22/

To view hidden text inside each of the preformatted text boxes below, scroll horizontally.


SOFTWARE_APPLICATION_COMPONENTS


python_source_file: https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_49/main/print_folder_checksums.py

plain_text_file: https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_49/main/test_folder_checksums.txt


PROGRAM_INTERPRETATION_AND_EXECUTION


STEP_0: Copy and paste the Python source code into a new text editor document and save that document as the following file name:

print_folder_checksums.py

STEP_1: Open a Unix command line terminal application and set the current directory to wherever the Python program file is located on the local machine (e.g. Desktop).

cd Desktop

STEP_2: Run the program by entering the following command:

python3 print_folder_checksums.py

STEP_3: If the program interpretation command does not work, then use the following commands (in top-down order) to install the Python interpreter:

sudo apt update
sudo apt install python3

STEP_4: Observe program results on the command line terminal and in the output file.


PROGRAM_SOURCE_CODE


Note that the text inside of each of the the preformatted text boxes below appears on this web page (while rendered correctly by the web browser) to be identical to the content of that preformatted text box text’s respective plain-text file or source code output file (whose Uniform Resource Locator is displayed as the green hyperlink immediately above that preformatted text box (if that hyperlink points to a source code file) or whose Uniform Resource Locator is displayed as the orange hyperlink immediately above that preformatted text box (if that hyperlink points to a plain-text file)).

(Note that angle brackets which resemble HTML tags (i.e. an “is less than” symbol (i.e. ‘<‘) followed by an “is greater than” symbol (i.e. ‘>’)) displayed on this web page have been replaced (at the source code level of this web page) with the Unicode symbols U+003C (which is rendered by the web browser as ‘<‘) and U+003E (which is rendered by the web browser as ‘>’). That is because the WordPress web page editor or web browser interprets a plain-text version of an “is less than” symbol followed by an “is greater than” symbol as being an opening HTML tag (which means that the WordPress web page editor or web browser deletes or fails to display those (plain-text) inequality symbols and the content between those (plain-text) inequality symbols)).

python_source_file: https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_49/main/print_folder_checksums.py


#########################################################################################
# file: print_folder_checksums.py
# type: Python
# date: 17_OCTOBER_2025
# author: karbytes
# license: PUBLIC_DOMAIN 
#########################################################################################

import os
import hashlib

# Define the only function in this program.
def list_file_checksums(folder_path, output_file):
    file_count = 0
    i = 0

    # Define the output file handler.
    with open(output_file, 'w') as f:

        # Print a horizontal divider line to the command line terminal and to the output file.
        print("\n\n--------------------------------")
        f.write("--------------------------------")

        # Print description to both terminal and file.
        print("\n\nThis Python program prints the SHA-256 checksum of each file inside of a particular folder.")
        f.write("\n\nThis Python program prints the SHA-256 checksum of each file inside of a particular folder.")

        # Print a horizontal divider line to the command line terminal and to the output file.
        print("\n\n--------------------------------")
        f.write("\n\n--------------------------------")

        # Walk through the folder and its subfolders.
        for root, dirs, files in os.walk(folder_path):
            f.write(f"\n\nDirectory: {root}")
            print(f"\n\nDirectory: {root}")
            for file in files:
                file_path = os.path.join(root, file)
                if os.path.isfile(file_path):  # Only process files, not subdirectories.
                    # Compute SHA-256 checksum.
                    sha256_hash = hashlib.sha256()
                    with open(file_path, "rb") as file_handle:
                        # Read and update hash in chunks of 4MB to handle large files efficiently.
                        for chunk in iter(lambda: file_handle.read(4 * 1024 * 1024), b""):
                            sha256_hash.update(chunk)
                    checksum = sha256_hash.hexdigest()
                    file_count += 1
                    f.write(f"\n\nfile_{i}: {file} // SHA-256: {checksum}")
                    print(f"\n\nfile_{i}: {file} // SHA-256: {checksum}")
                    i += 1
        
        # Print totals to the output file.
        f.write("\n\n--------------------------------")
        f.write(f"\n\nTotal number of files processed: {file_count}")
        f.write("\n\n--------------------------------")

        # Print totals to the command line terminal.
        print("\n\n--------------------------------")
        print(f"\n\nTotal number of files processed: {file_count}")
        print("\n\n--------------------------------")

    # Print a final message to the command line terminal.
    print(f"\n\nResults have been written to '{output_file}'.")

    # Print a horizontal divider line to the command line terminal.
    print("\n\n--------------------------------\n\n")

# Set the folder path to the folder you would like to analyze.
folder_path = 'test_folder'  # Replace with your actual folder path.
output_file = 'test_folder_checksums.txt'  # Output file (gets overwritten or created new).

# Execute the function which is defined in this program file.
list_file_checksums(folder_path, output_file)

SAMPLE_PROGRAM_OUTPUT


The text in the preformatted text box below was generated by one use case of the Python program featured in this computer programming tutorial web page.

plain_text_file: https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_49/main/test_folder_checksums.txt


--------------------------------

This Python program prints the SHA-256 checksum of each file inside of a particular folder.

--------------------------------

Directory: test_folder

file_0: green_hillside_castro_valley_02_may_2022.jpeg // SHA-256: 3b7ee332909f3943a3dc6184532969e613364296db8e7b54018a8d6bd251e34d

file_1: rocky_ridge_trail_via_las_trampas_wilderness_in_california_15august2025_p11.jpg // SHA-256: e27171fa32acaf92e41d1436f24037872c77958679d5dbd9273ea54740ae52e8

file_2: las_trampas_san_ramon_california_13may2025_p16.jpg // SHA-256: 7c90d17afede33edf7f96457b8fb43e183c1350590109c9983797abefc6fbac6

Directory: test_folder/folder_B

file_3: ramage_peak_trail_southwest_view_18_june_2022.jpg // SHA-256: 90f923de2335b8fba77e35f50eb0a0e9247ebb855b3f154676d5458b3aba9341

file_4: las_trampas_wilderness_in_california_13august2025_p0.jpg // SHA-256: 0096206545a39e2d63b1fb85271639ecd5b7ab51ed3a5372ca866d23aea72c4a

file_5: morning_sunlight_shines_through_oak_trees_castro_valley_california_10_june_2022.jpeg // SHA-256: 0c929a18deecddb728c315db4dca29b189e8f0a804f6367c97b79e685a4059c2

Directory: test_folder/folder_A

file_6: trees_on_a_hill_castro_valley_california_27_may_2022.png // SHA-256: 0ea7444917feb80ff1366cf0573d0290b81ea696a1fc7879ac1d17415b3a01fc

file_7: skeletal_thistle_flowers_trees_in_background_castro_valley_california_06_october_2022.jpg // SHA-256: 99985a3c6ddd8bb87870c618c19787baa66d5345c846c7cfd6af9d1c2a13f640

file_8: las_trampas_wilderness_in_california_13august2025_p3.mp4 // SHA-256: b2905a8202d6a90f8a53008c9011dafe60e54fc80189a27af062548dee954314

Directory: test_folder/folder_A/folder_A0

file_9: violet_flowers_amidst_golden_grass_castro_valley_california_30_may_2022.png // SHA-256: bba24cfacaecabbca8daf34399c1ccb4374f6b5bd059fe8db7ca5c8f30749c5a

file_10: snake_in_the_grass_castro_valley_california_20_september_2022.jpg // SHA-256: 8b0b7830052b1c7b2e9e827e44c3a8bc0dfabdb6232fe64ce106fa540c97f71f

--------------------------------

Total number of files processed: 11

--------------------------------

This web page was last updated on 17_OCTOBER_2025. The content displayed on this web page is licensed as PUBLIC_DOMAIN intellectual property.