PIL批量更改
1 # coding:utf-8 2 import os 3 4 """ 5 安装时装pillow,引用时还是PIL 6 """ 7 from PIL import Image 8 9 10 # bmp 转换为jpg 11 def bmpToJpg(file_path): 12 for fileName in os.listdir(file_path): 13 # print(fileName) 14 newFileName = fileName[0:fileName.find(".")]+".jpg" 15 print(newFileName) 16 im = Image.open(file_path+"\"+fileName) 17 im.save(file_path+"\"+newFileName) 18 19 20 # 删除原来的位图 21 def deleteImages(file_path, imageFormat): 22 command = "del "+file_path+"\*."+imageFormat 23 os.system(command) 24 25 26 def main(): 27 file_path = "D:\MyData\zhaohz4\Desktop\bmp" 28 bmpToJpg(file_path) 29 deleteImages(file_path, "bmp") 30 31 32 if __name__ == '__main__': 33 main()
bat/cmd文件批量修改(任意格式) :
文件内目录下新建bat格式文件,输入: ren *.bmp *.jpg ——>将所有后缀为bmp格式的文件修改为jpg格式。