Search code examples
windowscmddirectory

Windows 'dir' command, Order By Name AND <something>


We can see in a directory files ordered by Name in Windows Explorer.

If I try the same thing in the Windows command prompt it orders by name differently - correctly:

dir *.jpg /ON /B

cubierta.jpg
pag00.jpg
pag06.jpg
pag08.jpg
pag09.jpg
pag100.jpg
pag101.jpg
pag102.jpg
pag103.jpg
pag104.jpg
pag105.jpg
pag106.jpg
pag107.jpg
pag108.jpg
pag109.jpg
pag11.jpg, etc, etc, etc, ...

Is there a way to get dir to order by Name where it reads the numbers as a human would do?


Solution

  • Your best option (if possible) is to add enough leading zeros (two, in this case) to your smaller numbers so that the sort does come out as expected.