我正在尝试替换文件中的文本,但是所有文件都带有打开/关闭括号。
Get-ChildItem -Hidden -Filter *.nfo |
ForEach-Object {
$file = $_.Name
$file = $_.Name -replace '\[','`[' -replace '\]','`]'
$find = '<studio>StudioName</studio>'
$replace = '<studio>Studio Name</studio>'
(Get-Content $file).replace($find,$replace) | Set-Content $file
}
当我运行上述代码时,出现此错误
Set-Content : An object at the specified path ``[FileName``] Martic.nfo does not exist,or has been filtered by
the -Include or -Exclude parameter.
At line:12 char:54
+ ... Get-Content $file.replace($find,$replace) | Set-Content "$file"
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (System.String[]:String[]) [Set-Content],Exception
+ FullyQualifiedErrorId : ItemNotFound,microsoft.PowerShell.Commands.SetContentCommand