Hydra
Processing
import os import shutil def copy_images_and_parent_folder(source_folder, destination_folder): # Create the destination folder if it doesn't exist if not os.path.exists(destination_folder): os.makedirs(destination_folder) # Walk through the source folder and its subfolders for root, dirs, files in os.walk(source_folder): for file in files: # Check if the file is an image (based on file extension) if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')): source_path = os.path.join(root, file) destination_path = os.path.join(destination_folder, file) shutil.copy2(source_path, destination_path) print(f"Copied {file} to {destination_folder}") # Copy the parent folder from the source to the destination parent_folder = os.path.dirname(source_folder) parent_folder_name = os.path.basename(parent_folder) destination_parent_folder = os.path.join(destination_folder, parent_folder_name) if not os.path.exists(destination_parent_folder): shutil.copytree(parent_folder, destination_parent_folder) print(f"Copied parent folder: {parent_folder_name}") # Set the source folder path (change to the desired folder) source_folder_path = "/path/to/your/source/folder" # Set the destination folder path (create a new folder or use an existing one) destination_folder_path = "/path/to/your/destination/folder" # Call the function to copy images and the parent folder copy_images_and_parent_folder(source_folder_path, destination_folder_path) }();
Replace “/path/to/your/source/folder” with the actual path to the folder containing your images, and “/path/to/your/destination/folder” with the desired destination folder. This script will copy image files source to the destination.