FILE2 - 批量修改文件名

'''
Create on 2019年8月26日
@author:LIN
'''

import os

def rename(dirname,source_src,destin_src):
    for category in os.listdir(dirname):

        catdir = os.path.join(dirname,category)
        
        if category.find(source_src) == 0:
            newName = category.replace(source_src,destin_src)
            os.rename(category, newName)


if __name__ == "__main__":
    dirname = 'C:/Users/huang.lin/Desktop/python'
    source_src = 'YAC'
    destin_src = 'ZAC'
    rename(dirname,source_src,destin_src)
    

?mid=&wid=51824&sid=&tid=8555&rid=LOADED&custom1=mp.csdn.net&custom2=%2Fpostedit&t=1566811310083?mid=&wid=51824&sid=&tid=8555&rid=FINISHED&custom1=mp.csdn.net&t=1566811310083

posted @ 2021-08-08 03:16  linhuang  阅读(2)  评论(0编辑  收藏  举报  来源