我有100个增量文件夹。 E.g。
'20D, 0.5B001'...'20D, 0.5B002'
......一直到
'20D, 0.5B100'
每个文件夹都包含具有相同增量名称的文件。例如。 'Test_C1S0002001'...'Test_C1S0002002'
等。
我想将每个文件夹中的每个文件重命名为'002001'
I.e.只需在每个子文件夹中删除'Test_C1S0'
。我怎样才能做到这一点?
2 个答案:
答案 0 :(得分:0)
gci 'c:\path\' -File -Recurse | ren -NewName { $_ -replace 'Test_C1S0', '' }
(未测试的)
答案 1 :(得分:0)
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")}