import os
import xml.etree.ElementTree as ET
def find_xml_with_keyword(xml_folder, keyword):
matching_files = []
count = 0
for root, dirs, files in os.walk(xml_folder):
for file in files:
if file.endswith(".xml"):
xml_path = os.path.join(root, file)
tree = ET.parse(xml_path)
root_elem = tree.getroot()
for obj in root_elem.findall("object"):
name = obj.find("name").text
if keyword in name:
matching_files.append(file)
count += 1
break
return matching_files, count
# 定义xml文件夹路径和关键字
xml_folder = r"C:\Users\admin\Desktop\TP\TP\tp\xml"
keyword = "RMB_100"
# 执行查询
matching_files, count = find_xml_with_keyword(xml_folder, keyword)
# 输出包含关键字的文件名
for file in matching_files:
print(file)
# 输出统计结果
print("共找到", count, "个含有关键字的文件")
查询yolo标准的xml文件里边是否有某个标签
最新推荐文章于 2024-07-06 18:26:44 发布