1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

DO not sorting as requested in v19

Discussion in 'Support' started by WavSlave, Aug 6, 2016.

  1. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    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.
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,075
    Likes Received:
    30
    Odd! They all (e, s, d) work here in v15, v19, and v20, agreeing with DIR with the same sorting.
     
  3. Fross

    Joined:
    May 30, 2008
    Messages:
    231
    Likes Received:
    1
    I can confirm it works correctly in my v20 build 12 on Win10x64.

    Michael
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,036
    Likes Received:
    84
    Not reproducible here.

    What build of v19 are you running?

    Do you have an alias for DO?
     
  5. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    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.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,036
    Likes Received:
    84
    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. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    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.
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,036
    Likes Received:
    84
    The problem is that v19 (and v18, and v17) isn't removing the whitespace after the /[!...] argument before processing the next argument.

    So if you execute it like this:

    do f in /[!descript.ion]/o:e * (echo %f)

    it will work in v19 (& v18 & v17). I have fixed this in v20.
     
  9. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,038
    Likes Received:
    0
    Rex,

    I thought you always recommended using whitespace between each "/" argument; Is that no longer the case?

    TIA.
     
  10. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    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.
     
  11. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,036
    Likes Received:
    84
    I always recommend (usually require) whitespace between arguments. This is a special case (i.e., bug) in v19 that has already been addressed in v20.
     
  12. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    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.)
     

Share This Page