2

I'm try to replace a text inside a file but all of the files have open/close bracket.

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
    }

When I run above code i get this error

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
Lalajee
  • 139
  • 1
  • 9

0 Answers0