PIL批量更改
# coding:utf-8
import os
"""
安装时装pillow,引用时还是PIL
"""
from PIL import Image
# bmp 转换为jpg
def bmpToJpg(file_path):
for fileName in os.listdir(file_path):
# print(fileName)
newFileName = fileName[0:fileName.find(".")]+".jpg"
print(newFileName)
im = Image.open(file_path+"\\"+fileName)
im.save(file_path+"\\"+newFileName)
# 删除原来的位图
def deleteImages(file_path, imageFormat):
command = "del "+file_path+"\\*."+imageFormat
os.system(command)
def main():
file_path = "D:\\MyData\\zhaohz4\\Desktop\\bmp"
bmpToJpg(file_path)
deleteImages(file_path, "bmp")
if __name__ == '__main__':
main()
bat/cmd文件批量修改(任意格式) :
文件内目录下新建bat格式文件,输入: ren *.bmp *.jpg ——将所有后缀为bmp格式的文件修改为jpg格式。