import os
import shutil
source_folder = 'D:\codeagain\datasets\AF7/val'
destination_folder = 'D:\codeagain\datasets/7af/val'
# 自动创建输出目录
if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
# 遍历所有子文件夹
for parent_folder, _, file_names in os.walk(source_folder):
# 遍历当前子文件夹中的所有文件
for file_name in file_names:
# 只处理图片文件
if file_name.endswith(('jpg', 'jpeg', 'png', 'gif')):
# 构造源文件路径和目标文件路径
source_path = os.path.join(parent_folder, file_name)
destination_path = os.path.join(destination_folder, file_name)
# 复制文件到目标文件夹
shutil.copy(source_path, destination_path)
移动子文件夹图片到文件夹中
最新推荐文章于 2024-09-15 22:31:42 发布