powershell - 使用 Powershell 从文件名中删除前导零
问题描述
早上好。
我无法理解过去的主题。我是一个了解很少的新用户。
我想从其中的文件名中删除所有前导零的文件路径是这个。
CD 文件\附件
基本上我想做的是将该文件路径复制粘贴到Powershell中,然后复制粘贴一个命令以从该文件夹中的文件名中删除所有前导零。
文件名的示例为 0123456789xxxxxxxxxx(长度和字符不同)
我想要 123456789xxxxxx
任何帮助是极大的赞赏。
解决方案
正如Lee_Dailey 评论的那样,您可以使用该TrimStart()
方法从字符串中修剪前导字符:
# Change location to the folder
cd Documents\Attachments
# Discover all the files in the current folder with leading 0s in their name
$files = Get-ChildItem -File -Filter 0*
# Use `Rename-Item` with `TrimStart` to rename the files to the appropriate name without the leading 0s
$files |Rename-Item -NewName { $_.Name.TrimStart('0') }
推荐阅读
- c# - PostgreSQL 中的 ROW_NUMBER 查询?
- php - 如何将值传递给泛光灯自定义变量
- python - 如何将类绑定到另一个小部件
- api - SPA 隐式流 vs 授权流 vs 混合流
- f# - 将 F# (FSharp.Core 4.3.4) 类型提供程序与 .NET Core 2.1 一起使用
- java - 即使在 Java 中加载属性文件后,getProperty 也会返回 null
- excel - 带索引函数的条件百分位数
- php - 短信中的字符串中断(PHP)
- javascript - 使用jquery通过控制台添加创建列表
- angular - 未捕获(承诺):错误:StaticInjectorError(AppModule)[employeService -> Http]: