Untitled
unknown
python
a month ago
1.0 kB
4
Indexable
import os import shutil def find_and_copy_rename_jpgs(root_dir): # Walk through all directories and files in the root directory for dirpath, dirnames, filenames in os.walk(root_dir): for filename in filenames: if filename.lower().endswith('.jpg'): # Check if the file is a .jpg old_file_path = os.path.join(dirpath, filename) # Create a new name for the file, e.g., add "_copy" before the extension base_name, ext = os.path.splitext(filename) new_filename = f"{base_name}_copy{ext}" new_file_path = os.path.join(dirpath, new_filename) # Copy and rename the file shutil.copy(old_file_path, new_file_path) print(f"Copied and renamed: {old_file_path} to {new_file_path}") # Replace 'your_root_directory' with the path to your root directory find_and_copy_rename_jpgs('your_root_directory')
Editor is loading...
Leave a Comment