使用python批量处理修改图片命名

该程序是将某个路径下,Ubuntu的系统
/home/lid/share/cannypicture/image
的所有图片 不管是名称什么样的,排序如何
将其读取出来,并重新按1-无穷大的顺序进行批量修改。可以增加
前缀和后缀。比如jpg1.jpg


#coding:utf-8
import os

def ChangeFileName(path,Qianzui,Houzui):#, dist, pos_or_neg
    filelist = os.listdir(path)
    print("filelist:",filelist)
    count=0
    for file in filelist:
        print(file)
    for file in filelist:   
        Olddir=os.path.join(path,file)  
        if os.path.isdir(Olddir):  
            continue
        filename=os.path.splitext(file)[0]   
        filetype=os.path.splitext(file)[1]
        Newdir=os.path.join(path,Qianzui+str(count).zfill(1)+Houzui+filetype)  
        os.rename(Olddir,Newdir)
        count+=1

path = "/home/lid/share/cannypicture"      
ChangeFileName(path + "/image","jpg","") # 你的路径, 前缀,后缀
#ChangeFileName(path + "/com","jpg","")
#ChangeFileName(path + "/banzi","banzi","")

sitemap