I'm trying to add an XML declaration to multiple files in a directory. The code works for a single file with hard-coded name but when I want to run it for multiple files, I'm getting the following error:
"Exception calling "Save" with "1" argument(s): "The given path's format is not supported."
I'm using:
$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)
}
I've been changing the last line to
$xml.save($FilePath+"\"+$file)
$xml.save("$FilePath\$file")
and other formats but still getting the same error.