Elie Fayad
Elie Fayad

Reputation: 357

Powershell: replace special characters of file names

I should start off by saying that I am still a beginner in powershell scripting.

I am trying to rename all files recursively in a directory by replacing a "+" with a " " in the file name.

The command I use is: Get-ChildItem -File -Recurse | Rename-Item -NewName {$_.name -replace "+", " "} but doesn't work and gives me the following error: enter image description here

Instead if I do this: Get-ChildItem -File -Recurse | Rename-Item -NewName {$_.name -replace "a", " "} everything works well.

I think the problem is with the "+" character but can't find anything on the web that tackles this problem. Does anyone know how to represent it or how to solve this?

Upvotes: 0

Views: 1838

Answers (1)

flaxel
flaxel

Reputation: 4587

You must escape the plus sign and the command should work:

Get-ChildItem -File -Recurse | Rename-Item -NewName {$_.name -replace "\+", " "}

Upvotes: 2

Related Questions