I would like to rename a bunch of files in a given directory that are already present in ascending order to another line of consecutive ascending numbers. The goal is to close gaps in between and get rid of the preceding zeros.
For example, original files are named:
0,1,2,4,9
The output in this case should be:
1,2,3,4,5
Since I want to put them in the same folder, which creates a conflict as the filenames are partly the same. To solve this, I first renamed them to:
a(1,2,3,4,5)
and then back to the numeric expression as before. This works up to a number of 9 files but as I have more than 9 files in some directories, it creates another problem as the filenames are no integer I suppose, so for example, if I have the files:
1,6,11
the file 11 will be in second position and gets renamed to 2 instead of 3.
My script looks like this:
@echo off
setlocal enabledelayedexpansion
set /a count=1
for /f "tokens=*" %%A in ('dir /b *.png') do (
ren "%%a" a!count!.png
set /a count+=1
)
set /a count=1
for /f "tokens=*" %%A in ('dir /b *.png') do (
ren "%%a" !count!.png
set /a count+=1
)
Is it possible to adopt this so that the filenames are recognized as integers and 2-digit numbers will be recognized as such?