python 批量修改文件后缀

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 19 18:53:47 2018

@author: bdf
"""
import os
# 列出当前目录下所有的文件
files = os.listdir('.')
#print('files',files)
for filename in files:
    portion = os.path.splitext(filename)
    # 如果后缀是.SSM
    if portion[1] == ".SSM":  
        # 重新组合文件名和后缀名
        newname = portion[0] + ".txt"   
        os.rename(filename,newname)

猜你喜欢

转载自blog.csdn.net/qq_40806289/article/details/85105784
今日推荐