Sort list in progressive numerical order

Example file list:

  • 1.jpg
  • 2.jpg
  • 3.jpg
  • 22.jpg

simple loop to repeat list

for /r %j in (*.jpg) do @echo %~nxj

The result is the following:

1
2
22
3

How can I arrange the results sequentially as shown below?

1
2
3
22

thanks everyone

+4
source share
2 answers
@ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
(
FOR /f %%a IN ('dir /b /a-d "%sourcedir%\*.jpg" ') DO (
  SET /a seq=1000000000+%%~na
  ECHO !seq!) 
)>"%temp%\tempfile"

FOR /f %%a IN ('sort "%temp%\tempfile"') DO (
 SET /a seq=%%a-1000000000
  ECHO !seq!.jpg) 
)

GOTO :EOF

This should work for you - of course, you will need to install your own sourcedir, the temp file name is up to you, it will not be cleared, and it will only work with pure-numerical file names without leading zeros <1000000000 .jpg. An extension is assumed .

0
source

, , , .

@echo off
del /q /s /f "%temp%\TEMP.tmp">nul
dir /b *.* >> %temp%\TEMP.tmp
SetLocal EnableDelayedExpansion

for /f "delims=" %%x in ('type %temp%\TEMP.tmp') do ( 
    set "Var=%%x"
    ECHO !Var!
)
pause

bat , .

0

Source: https://habr.com/ru/post/1539773/


All Articles