原始格式:
需要将其顺序与前一文件夹连接起来
因此,改为从3690开始,如下:
代码:
# -*- coding:utf8 -*-import osclass BatchRename():'''批量重命名文件夹中的图片文件'''def __init__(self):self.path = r'C:\Users\Administrator\Desktop\cal\set00\V002' # 存放图片的文件夹路径def rename(self):filelist = os.listdir(self.path)total_num = len(filelist)i = 3690for item in filelist:if item.endswith('.jpg'): # 图片格式为jpgsrc = os.path.join(os.path.abspath(self.path), item)dst = os.path.join(os.path.abspath(self.path), str(i) + '.jpg') # 设置新的图片名称try:os.rename(src, dst)print("converting %s to %s ..." % (src, dst))i = i + 1except:continueprint("total %d to rename & converted %d jpgs" % (total_num, i))if __name__ == '__main__':demo = BatchRename()demo.rename()