Untitled

 avatar
unknown
python
a month ago
792 B
4
Indexable
import os
import shutil
import pathlib

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.casefold().endswith('.jpg'):  # Check if the file is a .jpg
                old_file = pathlib.Path(dirpath, filename)
                new_file = pathlib.Path(dirpath, 'folder.jpg')

                # Copy and rename the file
                # shutil.copy(old_file_path, new_file_path)
                print(f"Copied and renamed: {old_file} to {new_file}")

# Replace 'your_root_directory' with the path to your root directory
if __name__ == '__main__':
    find_and_copy_rename_jpgs('your_root_directory')
Editor is loading...
Leave a Comment