#utf-8
#authors 会飞的渔WZH
#time:2023-12-13
import os
# 要修改的图像所在的文件夹路径
root_path = r'D:\images\lines2\3' # 要修改的图像所在的文件夹路径
filelist = os.listdir(root_path) #遍历文件夹
print(len(filelist))
i=0
for item in filelist:
if item.endswith('.png'):
src = os.path.join(os.path.abspath(root_path), item) #原本的名称
print(src)
dst = os.path.join(os.path.abspath(root_path)+'_line_'+ str(i) + '.png')
# dst = os.path.join(os.path.abspath(root_path)+'_cuodian'+'_'+ str(i) + '.bmp')
# dst = os.path.join(os.path.abspath(root_path)+'_'+ str(i) +'_' + src.split('_')[5] +'.bmp')
# dst = os.path.join(os.path.abspath(root_path)+ str(i) +'_'+ src.split('_')[5] +'.bmp')
print(dst)
try:
os.rename(src, dst) #意思是将 src 替换为 dst
i+=1
print('rename from %s to %s' % (src, dst))
except:
continue
print('ending...')