I have a foler which contains a few thousand PDFs named like XXX_CON.100.1.pdf, XXX_CON.101.1.pdf etc. I just want to remove the characters 'XXX_' from all filenames but I simply cannot get this to work. I have tried the following commands:
Get-ChildItem | Rename-Item -NewName {$.Name -replace "XXX", "" }
Get-ChildItem -Filter 'XXX_*' | Rename-Item -NewName {$.name -replace 'XXX','' }
Get-ChildItem *.pdf | Rename-Item -NewName {$.name.substring(4,$.BaseName.length-4) + $_.Extension}
Get-ChildItem .pdf | Rename-Item -NewName { $_.Name -replace 'XXX_.pdf','*.pdf' }
ls | Where {$.FullName -match '(XXX)'} | Rename-Item -NewName { $_ -replace ("XXX_","") }
Every single command gives me the Powershell error "Rename-Item : The parameter is incorrect."
e.g:
Rename-Item : The parameter is incorrect. At line:1 char:23 + Get-ChildItem *.pdf | Rename-Item -NewName {$.name.substring(4,$.BaseName.leng ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (E:\TempPE\pdf\XXX_CON.99.1.pdf:String) [Rename-Item], IOException + FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
The crazy thing is if I run these with a -Whatif at the end they all appear to work... but when I take that parameter off they all fail again.
Anyone know what the issue is here? TBH I googled to get the examples above but I'm sure they should work yet none of them do and I'm not enough of a Powershell guru to know how to get this to work. It seems it just doesn't like Rename-Item no matter what I try which is really strange. Could it be because all the files have more than dot in them?