If you have a file name, such as “Committee of Minutes [October 2010] - hq.doc”, how can you force Powershell to replace the square brackets? The following does not work:
ls -filter *`[*`]* | foreach -Process { Rename-Item $_ -NewName ($_.Name -replace '\[', '\(') | Rename-Item $_ -NewName ($_.Name -replace '\]', '\)')}
I get an error message:
Rename-Item : Cannot rename because item at 'Committee minutes [October 2010] - hq.doc' does not exist. At line:1 char:53 + ls -filter *`[*`]* | foreach -Process { Rename-Item <<<< $_ -NewName ($_.Name -replace '\[' ]', '\)')} + CategoryInfo : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand
source share