Powershell batch rename files contained in [] resulted in error

All downloaded files are included in the "[download website address]", according to the conventional method

Get-ChildItem "D:\Bluey\" -Recurse |ForEach-Object{Rename-Item -Path $_.FullName -NewName $_.FullName.Replace('old','new')}

Reports have been unable to find the source file, access to that when the file name contains special characters, you need to use -LiteralPath parameters.

Get-ChildItem "D:\Bluey\" -Recurse |
Where-Object {$_.Name -match '\[.+\]' } |
foreach {
    Rename-Item -LiteralPath $_.FullName -NewName $($_.Name -replace '\[.+\]','-')
}

The [] characters therebetween and replaced -.

Guess you like

Origin blog.51cto.com/41084/2463237