代码伺候:
import osimport os.pathimport xml.dom.minidompath = r'D:/jingdiansuanfa/data_clean/LEVIR/three_class/only_three_voc'files = os.listdir(path) # 得到文件夹下所有文件名称s = []count = 0for xmlFile in files: # 遍历文件夹 if not os.path.isdir(xmlFile): # 判断是否是文件夹,不是文件夹才打开 name1 = xmlFile.split('.')[0] dom = xml.dom.minidom.parse(path + '/' + xmlFile) root = dom.documentElement newpath = root.getElementsByTagName('path') newpath[0].firstChild.data = 'VOCdevkitVOC2012JPEGImages' + '\' + name1 + '.jpg' with open(os.path.join(path, xmlFile), 'w') as fh: dom.writexml(fh) print('写入name/pose OK!') count = count + 1