In PowerShell, after cd'ing to the proper folder, try the follwoing command --- the 'whatif' parameter means nothing will happen, but it will tell you what it would do. If the output indicates the results you want, remove the '-whatif' and re-run the command.
If it seems off, post back & we can refine the command.
$i = 214
foreach ($file in gci *.png) {
rename-item $file ('M{0:000000}.png' -f $i++) -whatif
}
Or:
$i = [ref]214
gci *.png | rename-item -NewName {'M{0:000000}.png' -f $i.value++} -whatif
Keith
Hi Keith,
Thanks for the prompt reply. I banged heads with one of our scripting boffins and we came up with the following:
$i=214
Get-ChildItem *.png | %{Rename-Item $_ -NewName ('M{0:D6}.png' -f $i++)}
It worked perfectly except for appending 110 to the first 25 filenames (i.e., M000111 instead of M000001). Rage-making, right? Closer examination revealed the culprit: PowerShell and File Explorer approach numbering from opposing directions: File Explorer
lists files by 1,2,3...10,11,12, whereas PowerShell handles files by 1,10,11,2,20,21...
Because the original files were named image1, image2, image3... instead of image001, image002, image003, etc., PowerShell renamed them according to its own internal logic. Adding leading zeroes to the original file names fixed the issue when executing the
script. Good gravy, what a pain! But as Grandpa Orca was fond of saying, "Experience is what you get when you don't get what you want." You can bet we added this to the company wiki
tout de suite!
Thanks again for your help--it really put us on the right track!
-terry-