DO not sorting as requested in v19

#1
I ran an old v15-era batch file in v19 yesterday and got some unexpected results. I got the information I expected but in the wrong order. Some investigation quickly revealed that the sorting option I use on the batch's DO command isn't being honored in v19. It can easily be tested at the command line:

Code:
do f in /o:e * (echo %f)
Instead of being sorted by extension, the file list always comes back in alphabetical (by name) order. I also tried /O:S for a size sorting and /O:D for a date sorting but all I ever get back is a name sorting, as though I hadn't used the /O option at all. The same commands issued in v15 all sort properly. For what it's worth, other commands I tried that sort (e.g., DIR, FOR and SELECT) work as expected. Only DO seemed to have the issue in my limited testing.

Rex, I know all your current efforts are focused on v20 but if this is indeed a bug in v19, I hope it's not asking/hoping too much for a fix to the current version. I don't want to have to upgrade to the next major version right now simply because I found a bug right at the end of v19's life. Thanks in advance if you're willing to address this.
 
#5
Rats, I was really hoping this issue wasn't specific to me. I get different results from the same batch file and same test commands in side-by-side v15 and v19 windows.

Rex: 64-bit 19.00.52 on Win 7 Pro. No alias for DO, now or ever. I'll try going to 19.00.54, though I'm not expecting that to make a difference. I'll even try rebooting, but with similar expectations for that not to change anything. I'll tinker around a bit more and hope I didn't make a premature post.
 

rconn

Administrator
Staff member
May 14, 2008
10,742
97
#6
Rats, I was really hoping this issue wasn't specific to me. I get different results from the same batch file and same test commands in side-by-side v15 and v19 windows.
It would be pretty surprising if it was a v19 DO (only) issue, because there's only one routine that does the file sorting, and it's used by all of the file-handling commands (DO, DIR, FOR, etc.).
 
#7
Success! Well, success in the sense that I think I found the cause of failure. I played around with the very simple form of the command that I used in my original post pretty extensively at the prompt and had the sorting perform as requested every time, so I eventually revisited the original line of failing code in the batch file, an actual paste of which is as follows:

Code:
do filnam in /[!descript.ion] /a:-d /o:agen *
I need to use that exclusion range in this batch, as I don't want the hidden DESCRIPT.ION file to factor into its results. Playing around with that line, I discovered that the sorting works every time as long as I leave the exclusion range out. If I leave it in, I get a name sort every time no matter what I use after /O. The /A switch being included or excluded has no effect on the sorting, but adding /[!...] messes up the sorting every time. For what it's worth, anything specified in the exclusion range is, in fact, excluded. So the exclusion works but it seems to have the unintended secondary effect of nullifying the sorting, or so it seemed in my more rigorous testing.

As for my simplistic line of code in the original post, I may have pasted my line from the batch to the command line in my own tests (including the exclusion range, therefore resulting in sort failure) but simply didn't include it in the post because I didn't think it was a factor. The line that I used in the first post does indeed work, presumably because it doesn't use an exclusion range. But you have my exact line in this post, which seems to generate reproducible results.
 
#10
I admit to not fully understanding your explanation of the problem but I guess that's not necessary. I've edited the file, left a note in it as to why the options are all now mashed together (a habit I used to have which took a long time to break) and can confirm that all now works as expected.

Thanks for looking into it, Rex.
 
#12
Charles, yes, that's generally recommended even though it's not always essential. I still often write commands at the prompt that have no daylight in them, but I have tried to force myself to be more proper in my batch files. I figure the fewer ways my own coding might trip up the parser, the better life will be in general. I think in this particular instance, the recommendation to eliminate the whitespace is an isolated one that's merely a workaround for a minor bug. I'd prefer to see v19 fixed the same way v20 has been so as not to make that a necessity -- it's still the officially current version, after all -- but I'm not going to press that point. Rex can do as he pleases and I can live with it the way it is.

Heh, I can't help but smile remembering Rex being somewhat horrified at the option "grammar" in some of Steve Fabian's commands. Those exchanges were always fun to read. (That's no dig at Steve, of course, whom I still miss a lot here.)