将多个文件夹名称从%-%改为%(删除连字符后的所有内容)。

问题描述 投票:-1回答:1

我有一个包含多个子文件夹的文件夹,命名为.12345 - textfoldername。12345 - textfold name

我想重命名所有这些子文件夹,只保留第一个数字(12345),并删除所有其他的子文件夹(- textfoldername)。

我怎么能建立的Windows脚本。

谢谢你的帮助

windows bash powershell batch-rename
1个回答
0
投票

,使用 Get-ChildItem 来发现所有的子文件夹,然后用 Rename-Item 重命名。

Get-ChildItem path\to\root\directory -Directory |Rename-Item -NewName {$_.Name -replace ' - .+$'}

The -replace 操作者与删除 - 及其后现有名称中的任何内容(或,如果 - something 没有找到,忽略它)

© www.soinside.com 2019 - 2024. All rights reserved.