python 批量修改文件后缀

By | May 31, 2021

python一键批量修改文件后缀!

[cc lang=”python”]# python批量更换后缀名
import os

# 列出当前目录下所有的文件
files = os.listdir(‘.’)
for filename in files:
portion = os.path.splitext(filename)
# 如果后缀是.dat
if portion[1] == “.gif”:
# 重新组合文件名和后缀名
newname = portion[0] + “.png”
os.rename(filename,newname)[/cc]

Leave a Reply

Your email address will not be published.