Now we check target path subfolders as well if file already exists, for example in paths like I:\Photos\2026\04\20\_Not selected
This commit is contained in:
+27
-6
@@ -31,11 +31,31 @@ def get_exif_date(file_path):
|
||||
return "CRITICAL ERROR: exiftool command not found. Please ensure exiftool is installed and in your system PATH."
|
||||
|
||||
|
||||
def find_existing_file(base_path, filename):
|
||||
"""
|
||||
Check if a file already exists at base_path or any of its subdirectories.
|
||||
Returns the full path to the existing file, or None if not found.
|
||||
"""
|
||||
# First check the base_path directory itself
|
||||
candidate = os.path.join(base_path, filename)
|
||||
if os.path.exists(candidate):
|
||||
return candidate
|
||||
|
||||
# Then search all subdirectories recursively
|
||||
for foldername, subfolders, files in os.walk(base_path):
|
||||
for f in files:
|
||||
if f == filename:
|
||||
return os.path.join(foldername, f)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def scan_photos(root_dir, base_target_path):
|
||||
"""
|
||||
Recursively scans the given directory (root_dir), extracts EXIF date,
|
||||
prints file details with proposed destination paths, then asks for confirmation
|
||||
before copying files.
|
||||
before copying files. Before copying, it checks if the file already exists
|
||||
in the target date folder or any of its subdirectories.
|
||||
"""
|
||||
accepted_extensions = ('.jpg', '.jpeg', '.dng', '.raw', '.cr2', '.cr3', '.raf')
|
||||
|
||||
@@ -104,19 +124,20 @@ def scan_photos(root_dir, base_target_path):
|
||||
created_dirs_count = 0
|
||||
|
||||
for file_path, date_time_str, dest_dir in file_info_list:
|
||||
dest_file = os.path.join(dest_dir, os.path.basename(file_path))
|
||||
filename = os.path.basename(file_path)
|
||||
|
||||
# Create destination directory if it doesn't exist
|
||||
if not os.path.exists(dest_dir):
|
||||
os.makedirs(dest_dir)
|
||||
created_dirs_count += 1
|
||||
|
||||
# Check if file already exists in destination
|
||||
if os.path.exists(dest_file):
|
||||
print(f"File already exists: {dest_file} (skipped)")
|
||||
# Check if the file already exists in dest_dir or any of its subdirectories
|
||||
existing = find_existing_file(dest_dir, filename)
|
||||
if existing:
|
||||
print(f"File {filename} already exists at: {existing} (skipped)")
|
||||
skipped_exists_count += 1
|
||||
else:
|
||||
filename = os.path.basename(file_path)
|
||||
dest_file = os.path.join(dest_dir, filename)
|
||||
print("\n--- Starting copy of: " + filename + " ---")
|
||||
print("Source: " + file_path)
|
||||
print(f"Destination: {dest_file}")
|
||||
|
||||
Reference in New Issue
Block a user