home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / doshelp / helpsb.zoo / help / batch / for / examples.hlp next >
Encoding:
Text File  |  1989-01-01  |  2.0 KB  |  51 lines

  1. SAMPLE command and resulting output  | Comments about the output
  2.  
  3.   FOR %f IN (*.ASM) DO DIR %f        If there are two files in our current
  4.                     directory that end in .ASM, then this
  5.   DIR PRG1.ASM                command would be the same as entering:
  6. Volume in drive C is EXAMPLELABEL
  7. Directory of C:\                DIR PRG1.ASM
  8.                         DIR PRG2.ASM
  9. PRG1    ASM     25654  4-16-88   5:13p
  10.                     directly from the keyboard. Notice how
  11.      1 File(s)    8671447 bytes free    the DIR commands appear after the FOR,
  12.                     just as though they had been entered
  13.   DIR PRG2.ASM                from the keyboard. Alternatively, the
  14. Volume in drive C is EXAMPLELABEL    list can be entered directly in
  15. Directory of C:\            parentheses.  For example,
  16.  
  17. PRG2    ASM     31557  5-18-88   3:32p  FOR %f IN (PRG1.ASM PRG2.ASM) DO DIR %f
  18.                     would produce the same results.
  19.      1 File(s)    8671447 bytes free
  20.  
  21.    FOR %x IN (*.*) DO DEL %x > NUL    This does the same thing as DEL *.*,
  22.                     without asking "Are you sure (Y/N)?"
  23.  
  24.    FOR %%x IN (%1 %2) DO %%x *.BAS CON  If this line were in a batch file that
  25.                     had been executed with the first two
  26.   COPY *.BAS CON            parameters of COPY DEL, the FOR
  27.   DEL *.BAS CON             command would execute the two commands
  28.                     as shown. 
  29.  
  30.    FOR %%a IN (1 2) DO COMMAND /C FOR %%A IN (X y) DO ECHO %%a%%A
  31.  
  32. 1X                    FOR commands cannot be nested, but 
  33. 1y                    this is almost as good. Notice that
  34. 2X                    the FOR-variables are case sensitive:
  35. 2y                    %%a is NOT the same as %%A!
  36.  
  37.    FOR %%F IN (%PATH%) DO DIR %%F /P    This example would produce a directory
  38.                     listing for each directory contained 
  39.                     in the PATH environment variable.
  40.  
  41.    SET CASE=NONE
  42.    BACKUP C: A: /S
  43.    FOR %%E in (3 4) DO IF ERRORLEVEL %%E SET CASE=%%E
  44.    GOTO ERR%CASE%            This example works almost like a CASE
  45.                     statement, ECHOing an error message
  46.                     appropriate to the type of error 
  47.                     encountered during the disk backup
  48.                     (at label ERR3 or ERR4). However, if
  49.                     no error occured, normal processing
  50.                     at label ERRNONE will continue.
  51.