【发布时间】:2021-10-21 03:44:44
【问题描述】:
我对脚本很陌生,一直被这个问题困扰。
我想提取一个 zip 文件,在该 zip 文件中有一个名为 file.xml 的 xml 文件,我需要从中提取信息。
文件很大,我只需要提取两个标签之间的信息。
<Report name="result\_many fail" summary="20" yes=19 no="1" finished=20>
我需要提取标签名称和完成之间的信息并将其保存到 txt 文件中。 txt 文件应如下所示:
name result_many fail, summary 20, yes 19 , no 1, finished 20
问题在于它解压缩到正确的目标文件夹,但没有将任何内容保存到 result.txt 文件中。我的 txt 文件总是空的。
这是我的代码:
echo "unzipping file..."
powershell "Expand-Archive C:\path_to_zip_file -Destinationpath C:\path_to_to_destination_folder;
$Path = “C:\path_to_to_destination_folder\file.xml;”
Select-Xml -XPath '//Report[@finished]').Node.InnerText;
Set-Content -Path 'C:\path_to_to_destination_folder\result.txt'
@echo "done"
有人可以帮我吗?
【问题讨论】:
-
这是您实际使用的代码吗?它甚至不运行
-
您没有将
-Path设置为您的源xml 文档。请参阅Select-Xml 文档。 -
@SEarle1986 是的,它运行,它只是正确提取然后停止
-
我尝试时失败了。此行存在语法错误,因为您有
)Select-Xml -XPath '//Report[@finished]').Node.InnerText;
标签: powershell