BAT在文件夹里所有的 XML文件中将<ProductKeyID>后的13位字符和<HardwareHash>后的所有字符以及文件名字提取到txt
时间: 2024-09-08 16:00:40 浏览: 82
这是一个自动化脚本的任务,可以使用多种编程语言来完成,例如Python、PowerShell或者是批处理脚本。下面是一个使用Python语言的基本示例来说明如何完成这个任务。
Python脚本可以使用内置的`xml.etree.ElementTree`模块来解析XML文件,并使用标准库中的`os`和`re`模块来处理文件系统操作和正则表达式匹配。以下是一个简单的脚本示例:
```python
import os
import re
import xml.etree.ElementTree as ET
def extract_info_from_xml(xml_file):
# 解析XML文件
tree = ET.parse(xml_file)
root = tree.getroot()
# 使用正则表达式查找<ProductKeyID>和<HardwareHash>标签
product_key_id_match = re.search(r'<ProductKeyID>(\w{13})</ProductKeyID>', ET.tostring(root, encoding='unicode'))
hardware_hash_match = re.search(r'<HardwareHash>(.+?)</HardwareHash>', ET.tostring(root, encoding='unicode'))
product_key_id = product_key_id_match.group(1) if product_key_id_match else 'Not found'
hardware_hash = hardware_hash_match.group(1) if hardware_hash_match else 'Not found'
return product_key_id, hardware_hash
def write_to_txt(xml_file, product_key_id, hardware_hash):
# 提取文件名
filename = os.path.basename(xml_file)
# 写入到txt文件中
with open('extracted_info.txt', 'a') as file:
file.write(f"File: {filename}\n")
file.write(f"ProductKeyID: {product_key_id}\n")
file.write(f"HardwareHash: {hardware_hash}\n\n")
# 遍历文件夹中的所有XML文件
for xml_file in os.listdir('.'):
if xml_file.endswith('.xml'):
product_key_id, hardware_hash = extract_info_from_xml(xml_file)
write_to_txt(xml_file, product_key_id, hardware_hash)
```
在运行这个脚本之前,请确保你已经安装了Python,并且这个脚本有权限访问目标文件夹和文件。脚本会遍历当前目录下所有的XML文件,并从中提取`<ProductKeyID>`后的13位字符和`<HardwareHash>`后的所有字符,然后将这些信息连同文件名字一起写入到一个名为`extracted_info.txt`的文本文件中。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)