I have a series of files that I want to rename. I want to rename the files with padded zeroes (total of 3 characters) after the first occurrence of the "-" delimiter like the examples below:
Old Name Example 1: 101-1_File1_Project1-000-END.txt
Desired New Name Example 1: 101-001_File1_Project1-000-END.txt
Old Name Example 2: 101-28_File1_Project1-000-END.txt
Desired New Name Example 2: 101-028_File1_Project1-000-END.txt
PowerShell code below works for Example 1 and not for Example 2. For Example 2 the result is:
101-0028_File1_Project1-000-END.txt
I thought this situation is exactly what PadRight is supposed to handle where there will be no more than 3 characters to the right of the "-". Can someone please assist?
PowerShell:
gci "C:\Path\Folder-with-Files" | ren -n {[regex]::replace($_.basename, '(?<=^[^-]*)-', {"$args".PadRight(3, '0')})+ $_.extension}