导入必要的模块

import os import xml.etree.ElementTree as ET

定义要处理的文件夹路径

folder_path = r"C:\UX Performance\UX"

遍历文件夹下的所有文件

for file_name in os.listdir(folder_path): # 判断是否为.xml文件 if file_name.endswith(".xml"): # 打开xml文件 xml_file_path = os.path.join(folder_path, file_name) tree = ET.parse(xml_file_path) root = tree.getroot()

    # 查找目标标签
    display_name_tag = root.find(".//DisplayName[@_locID='1']")

    # 读取标签内容
    if display_name_tag is not None:
        display_name = display_name_tag.text

        # 修改文件名
        new_file_name = display_name + ".xml"
        new_file_path = os.path.join(folder_path, new_file_name)
        os.rename(xml_file_path, new_file_path)

        print(f"文件 {file_name} 的标签内容为 {display_name},已修改为 {new_file_name}"
用python语言编写:CUX PerformanceUX文件下有多个xml结尾的文件遍历每个xml文件将每个xml文件里的DisplayName _locID=1Boot performance Full BootDisplayName标签里的内容读取出来将每个xml文件的名字修改为读取出的内容

原文地址: https://www.cveoy.top/t/topic/cotE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录