I found similar commands to these online. I want to replace the parenthesis in my file names to either a space or empty string.
The files I'm trying to change look like the following:
Nehemiah (1).mp3
Nehemiah (2).mp3
Nehemiah (11).mp3
Really I'd like them too look like the following:
Nehemiah 01.mp3
Nehemiah 02.mp3
Nehemiah 11.mp3
Here are the scripts I've tried.
Dir | Rename-Item –NewName { $_.name –replace “(“,”” }
Dir *.mp3 | rename-item -newname { $_.name -replace " ("," " }
Neither of these work.
Here is the error message I'm getting.
Rename-Item : The input to the script block for parameter 'NewName' failed. The regular expression pattern ( is not valid. At line:1 char:34 + Dir *.mp3 | rename-item -newname { $_.name -replace " ("," " } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (C:\Users...ehemiah (1).mp3:PSObject) [Rename-Item], Parameter ndingException + FullyQualifiedErrorId : ScriptBlockArgumentInvocationFailed,Microsoft.PowerShell.Commands.RenameItemCommand
-replace
expects a regular expression pattern, you need to escape the(
:-replace [regex]::Escape(" (")," "
– Mathias R. Jessen