Command Prompt Scripting | 561
Scripting and
Automation
Save these commands into MultiDel.bat. Now, this simple batch file deletes
one or more filenames with a single command; it??™s used like this:
MultiDel file1.txt another.doc third.log
by cycling through the command-line parameters one by one using shift. It
repeats the same two lines (del %1 and shift) until the %1 variable is empty
(see ???Conditional Statements,??? next, for the use of the if statement), at
which point the batch file ends (using the exit command).
Conditional Statements
There are three versions of the if statement, which allow you to compare
values and check the existence of files. The first version, which is usually
used to test the value of a variable, is used as follows:
if "%1"=="help" goto SkipIt
Note the use of quotation marks around the variable name and the help
text, as well as the double equals signs, all of which are necessary here.
Notice also there??™s no then keyword, which those of you who are familiar
with VBScript might expect. If the batch file finds that the two sides are
equal, it executes everything on the right side of the statement; in this case,
it issues the goto command.
The second use of the IF command is to test the existence of a file:
if exist c:\windows\tips.txt goto SkipIt
If the file C:\Windows\tips.txt exists, the goto command will be executed.
Similarly, you can you can test for the absence of a file, as follows:
if not exist c:\autoexec.
Pages:
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782