批量修改文件夹JPEGImages中图片的名字 为voc2007数据集要求的格式

#-*-coding:utf-8-*-
import os
 
path_0 = "./**"


i=1
for item in os.listdir(path_0):
    old_name = os.path.join(path_0,item)
    new_name = os.path.join(path_0,(str(i).zfill(6)+'.jpg'))
    os.rename(old_name, new_name)
    i+=1

注:其中str(i).zfill(6)的作用是在i不足6位时,在其前面补0;

>>> i = '13'
>>> i.zfill(6)
'000013'

猜你喜欢

转载自blog.csdn.net/qq_32863339/article/details/85260188