PowerShell tip: rename all matching files so that plus characters are replaced with spaces

Posted: (EET/GMT+2)

 

Today, I had a simple need: I had a single folder full of files downloaded from the Internet, all of them which contained a plus character "+" in their filename instead of a space character. Well, I prefer readable filenames, so I wanted to quickly rename these files so that the plus character is replaced with a space character.

PowerShell would do a nice job here, and indeed it did. After realizing the plus character is a regular expression character, I figured out a nice, clean way to solve the problem.

Here's the PowerShell command:

dir *.pdf | ren -NewName {$_.name -replace "\+"," "}

This renamed all PDF files in the current folder so that all "+" characters are replaced with a space. Note that in PowerShell, the "dir" command is an alias to "Get-ChildItem" and "ren" is an alias to "Rename-Item".

Hope this helps!