python 批量修改文件名

import os
import sys
def rename():
    path=input("请输入路径:")
    count=1
    filelist=os.listdir(path)
    for files in filelist:
        ori_dir=os.path.join(path,files)
        if os.path.isdir(ori_dir):#跳过目录
            continue
        now_dir = os.path.join(path, 'SteroSR_x4_epoch'+str(count)+'.pth')
       
        os.rename(ori_dir,now_dir)
        count+=1
    print("一共修改了"+str(count-1)+"个文件")
rename()

 

 

 

 

 

修改1
now_dir = os.path.join(path, 'img_'+str(count).zfill(3)+'_4_HR'+'.png')#不满3位,右对齐,前面补零

 

posted on 2020-12-06 11:45  cltt  阅读(90)  评论(0编辑  收藏  举报

导航