From 0124f0f7a8492ad183708e8c48f4473cf8b0723f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20R=C3=A4s=C3=A4nen?= Date: Sun, 19 Apr 2026 08:26:08 +0300 Subject: [PATCH] Script will list all photos found on given drive --- photoimport.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 photoimport.py diff --git a/photoimport.py b/photoimport.py new file mode 100644 index 0000000..4c9aeea --- /dev/null +++ b/photoimport.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import os +import sys + +def scan_photos(root_dir): + """ + Recursively scans the given directory and lists all specified photo file types. + """ + # Define accepted extensions (in lowercase) + accepted_extensions = ( + '.jpg', '.jpeg', '.raf', '.dng', '.raw', '.cr2', '.cr3' + ) + + print(f"--- Starting scan in: {root_dir} ---") + found_files = [] + + try: + for foldername, subfolders, filenames in os.walk(root_dir): + for filename in filenames: + # Get the full path + full_path = os.path.join(foldername, filename) + + # Check the file extension + # os.path.splitext splits filename into (root, extension) + _, ext = os.path.splitext(filename) + + # Convert extension to lowercase for case-insensitive matching + if ext.lower() in accepted_extensions: + found_files.append(full_path) + + except FileNotFoundError: + print(f"Error: The path '{root_dir}' was not found. Please check the drive letter.") + return + except Exception as e: + print(f"An unexpected error occurred: {e}") + return + + if found_files: + print("\n--- Files Found ---") + for file_path in found_files: + print(file_path) + print(f"\n--- Scan complete. Found {len(found_files)} files. ---") + else: + print("\n--- Scan complete. No specified photo files found in this directory or its subdirectories. ---") + + +if __name__ == "__main__": + # Check if a directory path argument is provided + if len(sys.argv) != 2: + print("Usage: python photoimport.py ") + print("Example (for Windows): python photoimport.py Q:\\") + sys.exit(1) + + # The first argument (index 1) is the path + target_path = sys.argv[1] + + # Ensure the path ends with a directory separator if it's not empty + # This helps when the user types "Q:" instead of "Q:\" + if not target_path.endswith(os.sep): + target_path = target_path + os.sep + + scan_photos(target_path)