# -*- coding: utf-8 -*-
"""
Created on Tue Aug 18 13:10:22 2026

@author: chuffard
"""

# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 15:52:19 2026

@author: chuffard
"""
import os
import shutil


def copy_filtered_jpgs(source_folder, destination_folder):
    # Search string
    search_term = "ext"
    
    # Create destination if it doesn't exist
    if not os.path.exists(destination_folder):
        os.makedirs(destination_folder)

    # Walk through all subfolders
    for root, dirs, files in os.walk(source_folder):
        for filename in files:
            # Check for: 1. .jpg extension AND 2. "ext" in the name
            if filename.lower().endswith(".jpg") and search_term in filename.lower():
                source_path = os.path.join(root, filename)
                dest_path = os.path.join(destination_folder, filename)

                # Ignore if a file with the same name already exists in destination
                if not os.path.exists(dest_path):
                    shutil.copy2(source_path, dest_path)
                    print(f"Copied: {filename}")
                else:
                    print(f"Skipped (already exists): {filename}")
# Usage
copy_filtered_jpgs('W:/Deployments/MARS-2024', 'C:/SES_in')


