1. 程式人生 > >python 批量修改檔案字尾

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)