I want to shorten this file name from '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 - Short Circuit & Protective Device Coordination Study.txt'
I use the pound (#) sign to clip the front, and the text '(For Rushing Review)' to clip the end.
Get-ChildItem 'c:\*Rushing*.txt' | Rename-Item -NewName {$_.BaseName.substring($_.BaseName.lastindexof('(#') + 15, $_.BaseName.IndexOf('(For Rushing Review)')-$_.BaseName.lastindexof('(#') + 15)+$_.Extension }
But I get the error Rename-Item : The input to the script block for parameter 'NewName' failed. Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string. Parameter name: length"
Because of the variable length of the file name, I need to use a variable for the end of the substring.