Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD DO default order is /o:a and not /o:e (like stated in the help)

Dec
73
1
The help file states for the DO command (seems to be copy/paste from every other command like DIR):

/O:... Sort the files before processing.
n Sort by filename and extension, unless e is explicitly included. This is the default.
a Sort names and extensions in standard ASCII order, instead of numerically when numeric substrings are included in the name or extension.

For me (using latest TCC on Win10 x64) this is buggy with DO because /o:a seems to be the default - which can cause havoc if you expect getting the same order like with DIR (where /o:n seems to be the correct default) and don't set the /o: switch explicitly.

Code:
@echo off
@echo off
touch /cq "Test 1.txt"
touch /cq "Test 2.txt"
touch /cq "Test 10.txt"
echo ... default
do test in Test*.txt
    echo %test%
enddo
echo ... /o:n
do test in /o:n Test*.txt
    echo %test%
enddo
echo ... /o:a
do test in /o:a Test*.txt
    echo %test%
enddo

My output is:

Code:
... default
Test 1.txt
Test 10.txt
Test 2.txt
... /o:n
Test 1.txt
Test 2.txt
Test 10.txt
... /o:a
Test 1.txt
Test 10.txt
Test 2.txt
 
Neither one, actually. If you don't specify /O: then DO does not sort files, just returns them in the order they occur in the directory. On an NTFS volume, that will be very similar /O:A. On some other file system, say FAT, they could be in any order.
 
Simply, on NTFS the default sort orders for DIR and DO are different, /o:n for DIR, /o:a for DO. Is there more to it than that?

If an IMDISK ramdrive correctly emulates FAT and FAT32, the default orders for DIR an DO differ in the same way on those file systems also.

Code:
z:\> echo %@fstype[z:]
FAT

z:\> dir /b
number21.txt
number111.txt

z:\> do f in * ( echo %f )
number111.txt
number21.txt

Code:
z:\> echo %@fstype[z:]
FAT32

z:\> dir /b
number21.txt
number111.txt

z:\> do f in * ( echo %f )
number111.txt
number21.txt
 
DIR sorts by default (unless you use /O:U). DO does not sort by default (unless you use /O:...)
 
DIR sorts by default (unless you use /O:U). DO does not sort by default (unless you use /O:...)
Nevertheless, the help file doesn't seem to be correct - how can n be "This is the default." if there is no sorting at all?

Neither one, actually. If you don't specify /O: then DO does not sort files, just returns them in the order they occur in the directory. On an NTFS volume, that will be very similar /O:A. On some other file system, say FAT, they could be in any order.
Is sorting a least consistently different on ntfs, and what's "very similar" to /o:a - i.e. is ntfs sorting at least reliably numeric?

I'm trying to trace a bug that originated in not using any /o option with DO, because I expected n to be the default. I've ended up with joined audio files in the wrong order with input files like 1.mp3, 10.mp3, 2.mp3 - but am still hoping this problem doesn't concern file names ike 01.mp3, 02.mp3, 03.mp3, ...
 
Nevertheless, the help file doesn't seem to be correct - how can n be "This is the default." if there is no sorting at all?

In your original post, you suggested that that bit was copied and pasted from another command. That seems the most sensible explanation to me.
 
I reckon it wouldn't be hard for Rex to simply make /o:n the default for DO.

The same blurb from the help appears in the help for FOR. I wonder how it fares there (and maybe in other places). I never use FOR, and I like it so little that I'm not inclined to test it. Thanks for DO, Rex.
 

Similar threads

Replies
2
Views
2K
Back
Top