Page 1 of 1

DIR listing order

Posted: 06 Sep 2006 02:32
by Matice
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?

Posted: 13 Sep 2006 21:03
by DosItHelp
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?

RE:

Posted: 14 Sep 2006 03:08
by Matice
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?

Posted: 15 Sep 2006 11:02
by Helper
Try:

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

:wink: