Search code examples
powershellwindows-explorer

Bulk rename without changing the file type


I need to bulk rename files by adding "_Rev-" to the ends of the name. The file extension type of .pdf needs to stay the same. I've tried about 10 different variations to the below strings in PowerShell:

Get-ChildItem | Rename-Item -NewName {$_.Name + "_Rev-"} 
Get-ChildItem *.pdf | Rename-Item -NewName { $_.Name + "_Rev-" }

Instead of changing my file name from ##-##-####.pdf to ##-##-####_Rev-.pdf it changes it to ##-##-####.pdf_Rev-.

I've searched different topics but wasn't quite able to get to what I'm looking for.


Solution

  • Try using .BaseName and .Extension

    Get-Childitem *.pdf | Rename-Item -NewName {$_.BaseName + "_Rev-" + $_.Extension}