import os
import os.path
import xml.dom.minidom
path = r'D:\Project\Bi-Ye\data-xml\Monochamus-alternatus'
files = os.listdir(path) # 得到文件夹下所有文件名称
s = []
count = 0
for xmlFile in files: # 遍历文件夹
if not os.path.isdir(xmlFile): # 判断是否是文件夹,不是文件夹才打开
name1 = xmlFile.split('.')[0]
dom = xml.dom.minidom.parse(path + '/' + xmlFile)
root = dom.documentElement
newfolder = root.getElementsByTagName('name')
newfolder[0].firstChild.data = 'Monochamus_alternatus_Hope'
with open(os.path.join(path, xmlFile), 'w') as fh:
dom.writexml(fh)
print('已成功修改')
count = count + 1