I have hundred thousands files located in ~40 folders (these subfolders being located in a same super-folder which I am going to call 'test'). I have tried to use powershell to replace a syntax found in the folder name but also in the filenames.
Basically my folders and files contains the same string of characters "PXXXX_0" that I want to batch rename in "PXXXX_"
Here is the code I used to first map the files & folders of interest
cd C:\test
Get-ChildItem -Filter "*PXXXX_0*" -Recurse | Rename-Item -NewName {$_.name -replace 'PXXXX_0', 'PXXXX_'} -whatif
This gives me the right files and previewed action (e.g.
What if: Performing operation "Rename File" on Target "Item: C:\test\PXXXX_053\PXXXX_053_558.jpg Destination C:\test\PXXXX_053\PXXXX_53_558.jpg
So this seems to work, but only on the files inside the folders that I also want to rename.
Now if I launch the code without -whatif it appears that only the folder names are rename, not the files...
I pretty sure I have missed something but since I am not really familiar with this language, I am struggling to find the solution. I am using Powershell v1.0
Thanks for any help.
Best