I am trying to make batch file naming easier for my end users. In photographing our locations, we can sometimes have only 1 photo or 500 depending on the size of the location. The code below works beautifully to bulk rename our photos based on how many files are in the directory:
$prefix = "[SomePrefix]"
$files = Get-ChildItem
$id = 1
$files | foreach { Rename-Item -Path $_.fullname -NewName ( $prefix + ((($id++).tostring()).padleft(($files.count.tostring()).length) -replace ' ','0' ) + $_.extension) }
The code pads the photo file name with leading zeroes based on the number of files in the directory, i.e. 1, 2, 3, 4, 5 if the total amount is less than 9 files; 01, 02, 03, 04, 05 if the total amount of files is between 10 and 99; 001, 002, 003, 004, 005 if the total amount of files is between 100 and 999.
I need to modify this code so that it ALWAYS retains 3 leading zeroes 001, 002, 003, 004, 005 no matter the number of files in the directory. However, I do need the code to recurse through the existing directory so I can eliminate users having to organize their photos into different folders based on the number (0-9; 10-99; 100-999) and running separate lines of codes for each.
Example photo file name convention: PREFIX_001.jpg
Can anyone tell me how to modify the above code to suit my needs?