将文件夹内的部分子文件夹下的jpg图像复制到另一个文件夹中
python">import os
import shutildef copy_selected_jpg_files(source_folder, subfolders_to_copy, destination_folder):if not os.path.exists(destination_folder):os.makedirs(destination_folder)for subfolder in subfolders_to_copy:subfolder_path = os.path.join(source_folder, subfolder)if os.path.exists(subfolder_path) and os.path.isdir(subfolder_path):for file in os.listdir(subfolder_path):if file.lower().endswith('.jpg'):source_file_path = os.path.join(subfolder_path, file)destination_file_path = os.path.join(destination_folder, file)shutil.copy(source_file_path, destination_file_path)print(f"Copied: {source_file_path} to {destination_file_path}")else:print(f"Subfolder {subfolder_path} does not exist.")
source_folder = 'path/to/source_folder'
subfolders_to_copy = ['subfolder1', 'subfolder2']
destination_folder = 'path/to/destination_folder' copy_selected_jpg_files(source_folder, subfolders_to_copy, destination_folder)