SHORTIES\GETDRIVE.DOC ·
DOC ·
2.6 KB ·
1990-04-09 ·
from PCPlus_Issue-45_Jun-1990
GETDRIVE.COM
by Colin Hart
GetDrive stores the current drive and directory so that a batch file may
return there after invoking a second batch file or running a program through
DOS.
GetDrive does the following:
The program sends information to the default output device - normally the
screen. This information consists of the current drive designation
(A:, B:, C: etc), a return character, the characters CD \, the current
directory path and a second return. By redirecting the output, using the >
operator, the information can be sent to a named batch file. Calling that file
by name from within a batch file will then execute the DOS commands to return
the program to the drive and directory current when GetDrive was invoked.
Example:
If you are in the UTILS directory of drive C:, the command
GETDRIVE >C:\DRIVE.BAT
stores the commands
C: CR
CD \UTILS CR
in the file DRIVE.BAT in the root directory. The batch file that issues the
command can then change to another directory and or drive and execute whatever
other programs are required. When complete, the batch file can call DRIVE.BAT
to switch back to the original drive and directory - C:\UTILS.
WARNING DO NOT redirect the output of GetDrive to an existing file, or it will
overwrite its present contents without warning.
This program works with DOS versions 2.0 and above, but note the two ways of
running one batch file from within another, detailed as follows.
The command GETDRIVE /H displays a help screen.
Notes. Calling a batch file from another batch file, so that control returns
to the calling batch file when the called file finishes, is done in one of two
ways. This depends on the version of DOS being used. The following two examples
use the same filenames and paths as before.
For DOS up to and including version 3.2, the command from within a batch file
is:
COMMAND/C C:\DRIVE.BAT
This command makes DOS load another copy of COMMAND.COM, execute the DRIVE.BAT
file, drop the second copy of COMMAND.COM and continue executing the original
batch file.
For DOS version 3.3 and above, the command is:
CALL C:\DRIVE.BAT
This executes the DRIVE.BAT file and then continue executing the calling batch
file at the next command.
If you put the command C:\DRIVE.BAT in a batch file, DRIVE.BAT will run, but
control will not be returned to the calling batch file on completion. Instead,
the calling batch file will finish and you will be returned to the DOS prompt.