This is useful in cases like the for...in...do statement (described in the proceeding
section), which can only loop a single command.
In one batch file, called WriteIt.bat, type:
if "%1"=="" exit
if exist %1.txt del %1.txt
echo This is a text > %1.txt
Then, in another batch file, called Main.bat, type the following:
for %%i in ("Kang","Kodos","Serak") do call WriteIt.bat %%i
The single-line Main.bat batch file uses the call command to run the other
batch file, WriteIt.bat, three times. You could omit the call command, but
doing so would cause the whole process to end after the subordinate batch
file was run the first time. Don??™t ask me why.
When this pair of batch files is run, you should end up with three files,
Kang.txt, Kodos.txt, and Serak.txt, all containing the text, ???This is a text.???
The if statement and the for...in...do loop are explained in earlier sections.
Get to the Command Prompt Quickly
If you find yourself using the Command Prompt frequently, you??™ll probably
benefit from the following solution. Instead of having to use the cd command
to change to a given folder, you can simply open a Command Prompt
window on the fly in Explorer, already rooted in the selected folder.
1. Open the Registry Editor (see Chapter 3).
2. Expand the branches to HKEY_CLASSES_ROOT\Directory\shell. (See ???File
Type Associations,??? in Chapter 3, for details on the structure of this
branch.)
3. Create a new key by going to Edit ??? New ??? Key, and type cmd for the
name of this new key.
Pages:
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785