重命名多个子文件夹中的文件 [英] Renaming files in multiple subfolders

查看:154
本文介绍了重命名多个子文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有100个增量文件夹。例如,

I have 100 folders that are incremental. E.g.

'20D, 0.5B001'...'20D, 0.5B002'

...一直到

'20D, 0.5B100'

每个文件夹都包含具有相同增量名称的文件。例如。 'Test_C1S0002001'...'Test_C1S0002002'等。

Each of those folders contains files that have the same incremental names. E.g. 'Test_C1S0002001'...'Test_C1S0002002' etc.

我想重命名每个文件夹中的每个文件到'002001'即只需在每个子文件夹中删除‘Test_C1S0’。我怎样才能做到这一点?

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?

推荐答案

TessellatingHeckler 应该工作得很好。您不需要正则表达式,因为您将从行首删除一个简单的字符串。因此,使用相同的逻辑...

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")}

至少没有PowerShell v3.0,那么您需要这样做。

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")}

这篇关于重命名多个子文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆