import os
import re
# 文件地址,相对地址或者绝对地址,在这里用的绝对地址
path = r""
file_walk = os.walk(path)
fileNum = 0
filesPathList = []
for root, dirs, files in file_walk:
for file in files:
fileNum = fileNum + 1
filePath = root + '/' + file
# print(filePath)
filesPathList.append(filePath)
protion = os.path.splitext(filePath)
# 这里可以推广为其他的格式转换
if protion[1].lower() == '.png':
print("正在处理:" + filePath)
newFilePath = protion[0] + '.JPG'
os.rename(filePath, newFilePath)
print('转换完成!')
将文件中.png图片替换为.jpg
最新推荐文章于 2023-06-01 11:30:12 发布