Renaming files in the order of file name in ascending order

  batch-file, cmd, logic, scripting, windows

The below script will rename the files in the descending order

But i need to reverse the order while renaming (ascending)

Here is the script which take files (mp4) from the same folder of the script and renames into sequencial numbers.

@echo off
setlocal EnableDelayedExpansion
set i=0
for /f "tokens=* delims=* " %%a in ('dir /b /a-d /o-d *.mp4') do (
    set /a i+=1
    ren "%%a" "!i!.new"
)
ren *.new *.mp4

Currntly the script will output as

20.mp4
19.mp4
18.mp4
17.mp4...............
2.mp4 
1.mp4

I need like below

1.mp4
2.mp4
3.mp4.....
19.mp4
20.mp4

Source: Windows Questions

LEAVE A COMMENT