home *** CD-ROM | disk | FTP | other *** search
- SAMPLE command and resulting output | Comments about the output
-
- FOR %f IN (*.ASM) DO DIR %f If there are two files in our current
- directory that end in .ASM, then this
- DIR PRG1.ASM command would be the same as entering:
- Volume in drive C is EXAMPLELABEL
- Directory of C:\ DIR PRG1.ASM
- DIR PRG2.ASM
- PRG1 ASM 25654 4-16-88 5:13p
- directly from the keyboard. Notice how
- 1 File(s) 8671447 bytes free the DIR commands appear after the FOR,
- just as though they had been entered
- DIR PRG2.ASM from the keyboard. Alternatively, the
- Volume in drive C is EXAMPLELABEL list can be entered directly in
- Directory of C:\ parentheses. For example,
-
- PRG2 ASM 31557 5-18-88 3:32p FOR %f IN (PRG1.ASM PRG2.ASM) DO DIR %f
- would produce the same results.
- 1 File(s) 8671447 bytes free
-
- FOR %x IN (*.*) DO DEL %x > NUL This does the same thing as DEL *.*,
- without asking "Are you sure (Y/N)?"
-
- FOR %%x IN (%1 %2) DO %%x *.BAS CON If this line were in a batch file that
- had been executed with the first two
- COPY *.BAS CON parameters of COPY DEL, the FOR
- DEL *.BAS CON command would execute the two commands
- as shown.
-
- FOR %%a IN (1 2) DO COMMAND /C FOR %%A IN (X y) DO ECHO %%a%%A
-
- 1X FOR commands cannot be nested, but
- 1y this is almost as good. Notice that
- 2X the FOR-variables are case sensitive:
- 2y %%a is NOT the same as %%A!
-
- FOR %%F IN (%PATH%) DO DIR %%F /P This example would produce a directory
- listing for each directory contained
- in the PATH environment variable.
-
- SET CASE=NONE
- BACKUP C: A: /S
- FOR %%E in (3 4) DO IF ERRORLEVEL %%E SET CASE=%%E
- GOTO ERR%CASE% This example works almost like a CASE
- statement, ECHOing an error message
- appropriate to the type of error
- encountered during the disk backup
- (at label ERR3 or ERR4). However, if
- no error occured, normal processing
- at label ERRNONE will continue.