import os, sys
from PIL import Image
"""
将filePath文件下的图片保存在newFilePath文件夹下的相应子文件夹中
pic 是字典,存放每个图片要移到的子文件夹名
"""
def moveImg(filePath, newFilePath, pic):
filePath = unicode(filePath, "utf8")
newFilePath = unicode(newFilePath, "utf8")
for root, dirs, files in os.walk(filePath):
for f in files:
fl = filePath + '/' + f
img = Image.open(fl)
img.save(newFilePath + '/' + pic[f[:-4]] + '/' + f)
From: https://blog.csdn.net/u012319493/article/details/75913001