From: gazelle@shell.xmission.com   
      
   In article ,   
   Auric__ wrote:   
   >Harry Potter wrote:   
   >   
   >> __Auric: I see two bugs in your batch file. The first line should read:   
   >>   
   >> if "%%1"=="" goto end   
   >   
   >Pretty much anything would also work here -- I normally have '%1==' in my   
   >batches, not the oopsie I originally posted. As I said, I'm out of practice.   
   >   
   >> Then you have to end with:   
   >>   
   >>:end   
   >> pause   
   >>   
   >> The pause is only necessary if you want to read the batch file's output.   
   >   
   >It's funny. Lately I've been using certain programming languages that do in   
   >fact have an "end" keyword; that's what threw me off. Batches in fact have   
   >:EOF instead. (On NT systems, anyway; can't remember about 9x or DOS but it   
   >wouldn't surprise me if the answer was "no.")   
      
   Because "end" looks too much like it might be a keyword (even if it isn't),   
   I got in the habit of making my "end of the batch" label be ":the_end".   
      
   I got into this habit back in DOS/Win9x days, and have stuck with it. Of   
   course, in modern NT (CMD) days, it's not really necessary, since you can   
   just do: goto :EOF   
      
   BTW, yes, the colon is technically not necessary, but many batch writers   
   like to see it anyway, since it matches up with the label itself. Just   
   personal preference, of course, but I think it actually documented (in some   
   help file) that way.   
      
   >Also, pause would only necessary if run from the GUI; when run from the   
   >terminal it shouldn't be.   
      
   Correct. And it is an ugly hack, but one that has gained currency because   
   a lot of people don't deal with the command line. You even see this trope in   
   "regular" languages, like VB Basic, etc - people put in a "Press any key to   
   continue" followed by some form of "getkey()" in their VB programs, for   
   precisely this reason - so that if it is run inside some GUI, well, you   
   know the rest...   
      
   >The corrected batch is:   
   >   
   > if '%1==' goto :EOF   
   > cd /D "%1"   
   > copy *.ino *.txt   
   > for /d /r %%a in (*) do (   
   > cd "%%a"   
   > copy *.ino *.txt )   
   >   
   >The original botched version worked for me, so I had no reason to test   
   >things like "no arguments passed." (As I said, I did the whole thing in 30   
   >seconds.)   
      
   FWIW, I might do it like this (instead of testing %1 directly on its own   
   line):   
      
    cd /D "%1" || (   
    echo Arg is missing or invalid!   
    goto :EOF   
    )   
      
   --   
   The randomly chosen signature file that would have appeared here is more than 4   
   lines long. As such, it violates one or more Usenet RFCs. In order to remain   
   in compliance with said RFCs, the actual sig can be found at the following URL:   
    http://user.xmission.com/~gazelle/Sigs/DanaC   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|