Python—批量修改文件后缀名

版权声明:本文为作者的原创文章,转载请注明出处。 https://blog.csdn.net/u014421797/article/details/83242811

 对文件后缀名进行修改

import os

def file1_name(file_dir):
    '''
    批量修改文件后缀名
    ''' 
    for root, dirs, files in os.walk(file_dir):  
        for file in files: 
            oldname =  os.path.splitext(file)
            if oldname[1] == '.jpg':  
                 newname = oldname[0] + ".png"  
                 os.rename(str(root)+'\\'+file,str(root)+'\\'+newname)
                  
     
file1_name('E:\\GTEA_Dataset\\png\\002')

猜你喜欢

转载自blog.csdn.net/u014421797/article/details/83242811
今日推荐