【发布时间】:2020-11-11 06:52:20
【问题描述】:
我想将此文件名从“210 8th Waverly Updated Submittal (#26 0100-15.0 260100-015.00 - Short Circuit & Protective Device Coordination Study (For Rushing Review)).txt'中缩短
to '26 0100-15.0 260100-015.00 - 短路和保护装置协调研究.txt'
我使用井号 (#) 来剪裁前面,并使用文本“(For Rushing Review)”来剪裁结尾。
Get-ChildItem 'c:\*Rushing*.txt' | Rename-Item -NewName {$_.BaseName.substring($_.BaseName.lastindexof('(#') + 15, $_.BaseName.IndexOf('(For Rushing Review)')-$_.BaseName.lastindexof('(#') + 15)+$_.Extension }
但我收到错误 Rename-Item : 参数“NewName”的脚本块输入失败。使用“2”参数调用“子字符串”的异常:“索引和长度必须引用字符串中的位置。 参数名称:长度"
由于文件名的长度可变,我需要在子字符串的末尾使用一个变量。
【问题讨论】:
标签: powershell substring