63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
#!/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 <drive_path>")
|
|
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)
|