# coding:utf-8 import os ''' Modify the batch file name 批量修改文件名字 ''' def RenameFile(TheFile,search_str,to_name): le = len(search_str) for the_file in os.listdir(TheFile): if the_file.find(search_str) != -1: print the_file key = the_file.find(search_str) if key == 0: replace_name = to_name + the_file[le:] else: replace_name = the_file[0:key] + to_name + the_file[key+le:] os.rename(the_file,replace_name) if __name__ == '__main__': RenameFile('.','zzz','a')
RenameFile('.',search_str,to_name)
'.' --- 设置当前路径为目录
search_str --- 需要修改的文件名字
to_name --- 修改后的文件名字
浙公网安备 33010602011771号