Now paths are generated correctly
This commit is contained in:
+34
-18
@@ -19,13 +19,16 @@ def get_exif_date(file_path):
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
# The result should contain the date string on the first line.
|
||||
date_string = result.stdout.strip()
|
||||
# The result contains "CreateDate : 2026-04-19".
|
||||
# Extract only the value after the colon.
|
||||
output = result.stdout.strip()
|
||||
if ':' in output:
|
||||
date_string = output.split(':', 1)[1].strip()
|
||||
else:
|
||||
date_string = output
|
||||
if date_string:
|
||||
# Clean up potential trailing units or extra metadata lines
|
||||
cleaned_date = date_string.split('\n')[0].strip()
|
||||
# Replace '-' with '\' as requested
|
||||
return cleaned_date.replace('-', '\\')
|
||||
# Replace '-' with '\' as requested for path compatibility.
|
||||
return date_string.replace('-', '\\')
|
||||
return "Date not found in metadata."
|
||||
except subprocess.CalledProcessError as e:
|
||||
# This handles cases where exiftool fails (e.g., corrupted file)
|
||||
@@ -34,9 +37,10 @@ def get_exif_date(file_path):
|
||||
# This handles cases where 'exiftool' command is not found
|
||||
return "CRITICAL ERROR: exiftool command not found. Please ensure exiftool is installed and in your system PATH."
|
||||
|
||||
def scan_photos(root_dir):
|
||||
def scan_photos(root_dir, base_target_path):
|
||||
"""
|
||||
Recursively scans the given directory (root_dir), extracts EXIF date, and prints file details.
|
||||
Recursively scans the given directory (root_dir), extracts EXIF date, and prints file details,
|
||||
showing the proposed destination path based on the base_target_path.
|
||||
"""
|
||||
# Define accepted extensions (in lowercase)
|
||||
accepted_extensions = (
|
||||
@@ -68,22 +72,33 @@ def scan_photos(root_dir):
|
||||
|
||||
if found_files:
|
||||
print("\n========================================================")
|
||||
print("--- File Name & Creation Date/Time ---")
|
||||
print("--- File Name & Proposed Destination Directory ---")
|
||||
print("========================================================\n")
|
||||
|
||||
processed_count = 0
|
||||
for file_path in found_files:
|
||||
# Extract the date using the external tool
|
||||
date_time = get_exif_date(file_path)
|
||||
date_time_str = get_exif_date(file_path)
|
||||
|
||||
# Print the file name and the date/time
|
||||
print(f"File Name: {os.path.basename(file_path)}")
|
||||
print(f"Creation Date/Time: {date_time}")
|
||||
# 1. Construct the full destination directory path
|
||||
# The base_target_path is expected to end with a separator.
|
||||
# The date_time_str is in YYYY\MM\DD format (backslash-separated).
|
||||
|
||||
# Explicitly join with backslashes for Windows-style paths.
|
||||
if not base_target_path.endswith('\\'):
|
||||
destination_dir = base_target_path + '\\' + date_time_str
|
||||
else:
|
||||
destination_dir = base_target_path + date_time_str
|
||||
|
||||
print(f"File: {os.path.basename(file_path)}")
|
||||
print(f" -> Extracted Date: {date_time_str}")
|
||||
print(f" -> Proposed Destination Directory: {destination_dir}")
|
||||
print("-" * 40)
|
||||
processed_count += 1
|
||||
|
||||
print(f"\n========================================================")
|
||||
print(f"--- Scan complete. Processed {processed_count} files. ---")
|
||||
print(f"Files with the same date will point to the same destination directory.")
|
||||
else:
|
||||
print("\n--- Scan complete. No specified photo files found in this directory or its subdirectories. ---")
|
||||
|
||||
@@ -97,15 +112,16 @@ if __name__ == "__main__":
|
||||
|
||||
# Argument 1: The directory to scan (the drive)
|
||||
root_scan_dir = sys.argv[1]
|
||||
# Argument 2: The path to display to the user
|
||||
target_display_path = sys.argv[2]
|
||||
# Argument 2: The path to display to the user (the base path for grouping)
|
||||
base_target_path = sys.argv[2]
|
||||
|
||||
# Echo the specified path
|
||||
print(f"Using path: {target_display_path}")
|
||||
print(f"Using base target path for grouping: {base_target_path}")
|
||||
|
||||
# Ensure the scanning path ends with a directory separator
|
||||
# This is important for os.path.join to work correctly
|
||||
if not root_scan_dir.endswith(os.sep):
|
||||
root_scan_dir = root_scan_dir + os.sep
|
||||
|
||||
# Perform the scan using the first argument (the drive)
|
||||
scan_photos(root_scan_dir)
|
||||
# Perform the scan using the first argument (the drive) and the base path
|
||||
scan_photos(root_scan_dir, base_target_path)
|
||||
Reference in New Issue
Block a user