欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python---将一个文件夹下的图片移到另一个文件夹

程序员文章站 2022-05-18 20:30:03
...
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) 

上一篇: PHP关键字

下一篇: PHP关键字