DIR listing order

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matice

DIR listing order

#1 Post by Matice » 06 Sep 2006 02:32

Greetings,

are there any means of functions that can be used so that the dir output or equivilent would order the files in human order hence:

currently if you have a directory with files named such as file1 thru 30,
the dir would list and sort by the first number and not in number sequence.

i need for the output to be in sequence,

any ideas?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 13 Sep 2006 21:03

Matice,

Go to "Batch Files" "11 - Sorting text with numbers" and download the sortn.bat file.
http://www.dostips.com/DtCodeBatchFiles.php#_Toc145951142

Then from a command line pipe the output of a dir command into sortn.bat like this:

Code: Select all

dir /b|sortn


Make sure sortn.bat is accessible if not use the full path name e.g.:

Code: Select all

dir /b|c:\sortn


This was a nice exercice :D
Does it solve your problem?

Matice

RE:

#3 Post by Matice » 14 Sep 2006 03:08

I must hand it to you, you did a great job with that. you are the GURU!

here is a next question!
in bash one can perform a sequence in loops, can the same be done in dos?

something like
instead of
for %%I in ( 1 2 3 4 5 6 7 8 9 ) do echo %%I
have something like
for %%I in (inc 1 9) do echo %%I

regards
Matice


DosItHelp wrote:Matice,

Go to "Batch Files" "11 - Sorting text with numbers" and download the sortn.bat file.
http://www.dostips.com/DtCodeBatchFiles.php#_Toc145951142

Then from a command line pipe the output of a dir command into sortn.bat like this:

Code: Select all

dir /b|sortn


Make sure sortn.bat is accessible if not use the full path name e.g.:

Code: Select all

dir /b|c:\sortn


This was a nice exercice :D
Does it solve your problem?

Helper

#4 Post by Helper » 15 Sep 2006 11:02

Try:

No problem:
for /L %%I in (1,1,9) do echo %%I

:wink:

Post Reply