【发布时间】:2015-08-06 14:58:45
【问题描述】:
我正在尝试将 XML 声明添加到目录中的多个文件。该代码适用于具有硬编码名称的单个文件,但是当我想为多个文件运行它时,我收到以下错误:
“使用“1”参数调用“保存”的异常:“给定路径的 不支持格式。”
我正在使用:
$FilePath = C:\test
$files = Get-ChildItem $FilePath\*.xml
foreach ($file in $files)
{
$xml = [xml](get-content $file)
$decl = $xml.CreateXmlDeclaration("1.0", "ucs-2", "yes")
$xml.InsertBefore($decl, $xml.DocumentElement)
$xml.save($FilePath$file)
}
我一直把最后一行改成
$xml.save($FilePath+"\"+$file)
$xml.save("$FilePath\$file")
和其他格式,但仍然出现相同的错误。
【问题讨论】:
标签: xml powershell