使用带有方括号的路径的Powershell脚本

我正在尝试替换文件中的文本,但是所有文件都带有打开/关闭括号。

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
david_ye007 回答:使用带有方括号的路径的Powershell脚本

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3132686.html

大家都在问