I have 100 folders that are incremental. E.g.
'20D, 0.5B001'...'20D, 0.5B002'
...all the way to
'20D, 0.5B100'
Each of those folders contains files that have the same incremental names. E.g. 'Test_C1S0002001'...'Test_C1S0002002'
etc.
I want to rename every file in each of these folders to '002001'
I.e. just get rid of 'Test_C1S0'
in every one of these subfolders. How can I do this?
gci 'c:\path\' -File -Recurse | ren -NewName { $_ -replace 'Test_C1S0', '' }
(untested)
What TessellatingHeckler has should work perfectly fine. You don't need regex for this as you are removing a simple string from the beginning of the line. So using the same logic...
Get-ChildItem "C:\temp" -Recurse -File | Rename-Item {($_.Name).TrimStart("Test_C1S0")}
If you don't have PowerShell at least v3.0 then you would need to do this.
Get-ChildItem "C:\temp" -Recurse | Where-Object{!$_.PSIsContainer} | Rename-Item {($_.Name).TrimStart("Test_C1S0")}