用python,将一个文件夹下所有子文件中的图片移到其他文件夹下:

import os
import shutil
path='原来文件夹的目录'
new_path='新文件夹的目录'

for root ,dirs,files in os.walk(path):
    for i in range(len(files)):
        if (files[i][-3:] == 'jpg') or (files[i][-3:] == 'png')or (files[i][-3:] == 'PNG') or (files[i][-3:] == 'JPG'):
            file_path = root +'/'+files[i]
            new_file_path = new_path+'/'+files[i]
            shutil.copy(file_path,new_file_path)


你可能感兴趣的:(毕业设计)