// Edit
Inspired by @Keith Miller's idea of using a descending/reverse loop to rename files in cmd/bat:
set "_n=" & set "_c=" & <nul (for /l %i in (99 -1 16)do set/a "_c=100%~i-15, _n=100%~i" && cmd/v/c "ren "!_c:~-2!.*.ext" "!_n:~-2!.*.ext"")
To do the same in PowerShell:
$i=(ls *.ext).count+16 ; For($i -eq 15; $i--) {
$old=($i-15).ToString("00") ; ls $($old+'. *.ext')|
% {ren $_ -new ($_.Name.Replace("$old. ","$i. "))}}
Edit //
set "_n=" & for /l %i in (1 1 84)do @set "_n=00%~i" && @cmd/v/c "ren "!_n:~-2!.*.ext" "!_n:~-3!.*.ext""
set "_n=" & set "_c=" & >nul (for /l %i in (1 1 84)do @set/a "_c=1000%~i+15" && @set/a "_n=1000+%~i" && @cmd/v/c "ren "!_n:~-3!.*.ext" "!_c:~-2!.*.ext"")
You can do this in command line too:
Obs.:1. Assuming that when renaming two-digit numbers
Obs.:2. Your folder has a total of 84 files = 100 - 16
Obs.:3. All files have the same extension.
1. First, add a digit to each file, renaming 16. file.ext -> 016. file.ext, thus avoiding conflict when renaming 01. file.ext for the name of 16. file.ext (existing file)
set "_n=" & for /l %i in (1 1 84)do @set "_n=00%~i" && @cmd/v/c "ren "!_n:~-2!.*.ext" "!_n:~-3!.*.ext""
Obs.:4. Use For /L loop from 1 to 84, define _n=001, when adding 00, in the front variable %i, a substring of maximum length 2 (file source "!_n:~-2!.*.ext") and a substring of maximum length 3 (file target "!_n:~-3!.*.ext") will be used by ren for rename your files in loop:
2. Use again a For /L loop from 1 to 84, define _c=1000%~i+15, when adding 1000, adding to the variable %i, a substring of maximum length 3 (file source "!_c:~-3!.*.ext") and a substring of maximum length 3 (file target "!_n:~-2!.*.ext") will be used by ren for rename your files in loop:
for /l %i in (1 1 84)do @set/a "_c=1000%~i+15" && @set/a "_n=1000+%~i" && @cmd/v/c "ren "!_n:~-3!.*.ext" "!_c:~-2!.*.ext""
Obs.:5. The result in the loop will be from 1 to 84:
ren 001.file.ext 16.file.ext
ren 002.file.ext 17.file.ext
ren 003.file.ext 18.file.ext
...
ren 084.file.ext 99.file.ext
Obs.:6. This can easily be expanded to 1 to 840, 1 to 8400, ...:
for /l %i in (1 1 840)do ...
... set "_n=000%~i"
... cmd/v/c "ren "!_n:~-3!.*.ext" "!_n:~-4!.*.ext""
for /l %i in (1 1 840)do ...
... set/a "_c=10000%~i+15"
... set/a "_n=10000+%~i"
... cmd/v/c "ren "!_n:~-4!..ext" "!_c:~-3!..ext"")
The same in Bat/CMD:
@echo off && cd /d "%~dp0"
set "_n=" & for /l %%i in (1 1 84
)do set "_n=00%%~i" && cmd/v/c "ren "!_n:~-2!..ext" "!_n:~-3!..ext""
set "_n=" & set "_c=" & >nul (for /l %%i in (1 1 84
)do set/a "_c=1000%%~i+15, _n=1000+%%~i" && cmd/v/c "ren "!_n:~-3!..ext" "!_c:~-2!..ext"")