python将.png图片改为.JPG格式

# 日常使用代码:将某个文件夹及其子目录下的所有.png图片改为.JPG格式
import os
import re

path=r"G:\"
file_walk = os.walk(path)
fileNum = 0
filesPathList = []
for root, dirs, files in file_walk:
    # print(root, end=',')
    # print(dirs, end=',')
    # print(files)
    for file in files:
        fileNum = fileNum + 1
        filePath = root + '/' + file
        # print(filePath)
        filesPathList.append(filePath)
        protion = os.path.splitext(filePath)
        # print(protion[0],protion[1])

        if protion[1].lower() == '.png':
            print("正在处理:" + filePath)
            newFilePath = protion[0] + '.JPG'
            os.rename(filePath, newFilePath)
            
print('done')
    原文作者:七度银尘
    原文地址: https://blog.csdn.net/weixin_42610407/article/details/99550626
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞