python将一个文件夹下的所有图片复制到另一个文件夹下

import os
import shutil
path = 'C:/flower/split_data/train'
new_path ='C:/flower/split_data'
for root, dirs, files in os.walk(path):
    for i in range(len(files)):
        if (files[i][-3:] == 'jpg'):
            file_path = root + '/' + files[i]
            new_file_path = new_path + '/' + files[i]
            shutil.copy(file_path, new_file_path)


你可能感兴趣的:(python将一个文件夹下的所有图片复制到另一个文件夹下)