Use python to rename images in a folder

#_*_coding:utf-8
import them

pic_path="/home/wlw/VS_code_projects/my_picture"

def rename():
    piclist=os.listdir(pic_path)
    total_num=len(piclist)
   
    i=1
    for pic in piclist:
        if pic.endswith(".jpg"):
            old_path=os.path.join(os.path.abspath(pic_path),pic)
            new_path=os.path.join(os.path.abspath(pic_path),'000'+format(str(i),'0>3')+'.jpg')

            os.renames(old_path,new_path)
            print u"Convert the original image naming format: "+old_path+u" to the new image naming format: "+new_path
            #print "Convert the original image path: %s to the new image path: %s" %(old_path,new_path)
            i=i+1
    
    print "Total "+str(total_num)+" pictures are renamed to:" "000001.jpg~"+'000'+format(str(i-1),'0>3')+".jpg form "

rename()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324595442&siteId=291194637