python re模块给图片统一命名

将文件夹下原1.jpg,2.jpg,统一命名为000001.jpg,000002.jpg,,,,,

//dire 路径,2802改为图片数量
import os
import numpy as np
import re

dire = r'E:\pic\20180729'
#input_folder='/home/XXX/tensorflow/Python-Machine-Learning-Cookbook-master/Chapter09/training_images'
a=os.listdir(dire)
c=[]

for i in range(2802):
    a[i]=dire+'\\'+a[i]
    print(a[i])
b=[0*i for i in range(2802)]
pos = 6
for i in range(2802):
    c = str(i)
    ze = pos-len(c)
    b[i] = '0'*ze+str(i)
    b[i]=dire +'\\'+b[i]+'.jpg'
    os.rename(a[i],b[i])

你可能感兴趣的:(python)