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

  1. SAMPLE BATCH file contents               | Comments about the output
  2.  
  3.                                            In the first IF, notice how an
  4.                                            undefined variable is detected.
  5.   IF x%DEFAULT%==x SET DEFAULT=C:          The contents of any disk drive
  6.   BACKUP %DEFAULT%\ A: /S                  could be backed up, no matter what
  7.                                            the current DOS disk drive was,
  8.                                            and without having to remember the 
  9.                                            option to get subdirectories backed
  10.                                            up.
  11.  
  12.   ECHO DELETING *.BAK FILES                For each subdirectory listed in the
  13.   FOR %%f IN (%PATH%) DO DEL %%f\*.BAK     PATH variable, all files with an 
  14.                                            extension of .BAK would be deleted.
  15.  
  16.  
  17.   IF %SCREEN% == MONO GOTO COLOR           If the variable SCREEN is not
  18.   IF %SCREEN% == COLOR GOTO MONO           defined, neither IF condition
  19.   :COLOR                                   would be true, and SCREEN would
  20.   SET SCREEN=COLOR                         be set to COLOR. Notice that there
  21.   MODE CO80                                are no spaces around '=' in SET.
  22.   EXIT                                     The EXIT would terminate processing
  23.   :MONO                                    of the BATCH file at this point.
  24.   SET SCREEN=MONO                          The next time the BATCH file was
  25.   MODE MONO                                executed, the second IF condition
  26.   EXIT                                     would be true, and SCREEN would be
  27.                                            reSET to MONO. 
  28.  
  29.  
  30.   IF x%RETURN%==x GOTO NEWSTART            In a complicated BATCH file which
  31.   IF %RETURN%==1 GOTO CONTINUE1            was executed several times, but 
  32.   IF %RETURN%==2 GOTO CONTINUE2            needed to remember that it had
  33.   GOTO EEXXIITT                            previously done some processing, an
  34.   :NEWSTART                                environment variable could be used
  35.   SET RETURN=1                             to control its execution. The first
  36.   ...do some initialization processing...  execution after a reboot of the 
  37.   GOTO EEXXIITT                            computer could do some initial 
  38.   :CONTINUE1                               processing, and then every 
  39.   ...do some intermediate processing...    subsequent execution would do some
  40.   ...if appropriate, SET RETURN=2          repetitive processing, until it
  41.   GOTO EEXXIITT                            decided that no repetitions were
  42.   :CONTINUE2                               necessary. Then it could do some
  43.   SET RETURN=                              final processing (which might even
  44.   ...do some termination processing...     include forcing a reboot of the
  45.   :EEXXIITT                                computer). Every time the BATCH file
  46.   ...do some common processing...          was executed, it could always do
  47.   EXIT                                     some common processing. The final
  48.                                            EXIT statement is not required.
  49. 
  50.