Note: This code will modify the original file name, it is recommended to make a backup
Target:
Change both the image and xml file names to file names starting with td_ and increasing numbers.
result:
code:
import os
name = 'td_' # 文件前缀名
cur = 1 # 递增
for filename in os.listdir("F:\\Dataset\\images\\"):
os.rename("F:\\Dataset\\images\\"+filename,
"F:\\Dataset\\images\\"+name + str(cur) + ".jpg")
os.rename("F:\\Dataset\\annotations\\" + filename[:-4] + ".xml",
"F:\\Dataset\\annotations\\" +name + str(cur) + ".xml")
cur += 1
print("------------------finish--------------------")