import os
new_names = ["apple", "banana", "orange"]
path = "./ocr_masks/" # 修改为你自己的图片路径
for i, filename in enumerate(os.listdir(path)):
# print('查看文件名:', filename)
for name in mask_list:
adjust_name = filename.split('.')[0]
if adjust_name in name:
new_filename = name.split('/')[-1]
os.rename(os.path.join(path, filename), os.path.join(path, new_filename))
print('查看改前和改后文件名: ', filename, new_filename)
第二次使用:
import os
new_names = ["apple", "banana", "orange"]
path = "./aim_pic/" # 修改为你自己的图片路径
for i, filename in enumerate(os.listdir(path)):
print('查看文件名:', filename)
k = int(filename.split('-')[0])
new_filename = mask_list[k].split('/')[-1]
os.rename(os.path.join(path, filename), os.path.join(path, new_filename))
print('查看改前和改后文件名: ', filename, new_filename)