python批量对文件夹下的图片重命名

# -*- coding:utf-8 -*-
import os
path = 'D:/ICDAR_Data/ICDAR2015/ICDAR2015_Data/ch4_training_images/'
filelist = os.listdir(path)
for item in filelist:
    # print('item name is ',item)
    if item.endswith('.jpg'):
        name = item.split('.',1)[0]
        src = os.path.join(os.path.abspath(path), item)
        dst = os.path.join(os.path.abspath(path), 'gt_' + name + '.jpg')
    try:
        os.rename(src, dst)
        print('rename from %s to %s' %(src, dst))
    except:
        continue

你可能感兴趣的:(python,深度学习)