Renaming files in multiple subfolders

2019-09-10 09:27发布

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?

2条回答
Summer. ? 凉城
2楼-- · 2019-09-10 10:14

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")}
查看更多
萌系小妹纸
3楼-- · 2019-09-10 10:29
gci 'c:\path\' -File -Recurse | ren -NewName { $_ -replace 'Test_C1S0', '' }

(untested)

查看更多
登录 后发表回答