[comp.binaries.ibm.pc] Change the path "on the fly".

emb978@leah.albany.edu (Eric M. Boehm) (06/29/88)

[ Note that they assume switchar=-.  Also, they only change the local
environment, not the global one, so running them from an inferior command.com
don't affect the original command.com.  This can be good or bad.  -russ ]

This is a posting of batch files to change your path "on the fly".  They
were taken from a PC Magazine article. I don't have the reference right now,
but if it is needed, I can submit it.

The main file, CHPATH.BAT, is fairly simple. If you type "CHPATH" with no
arguments or the wrong arguments, it will print out a help message.

Note that the old path is saved in RESTORE.BAT. If you hop around a lot, you
will end up with quite a few RESTORE.BATs floating around your hard disk.
You may want to change it to write the file in a specific directory.

ERIC M. BOEHM
EMB978@ALBNY1VX.BITNET
EMB978@LEAH.ALBANY.EDU


-------------------------------------------------------------------------------
ECHO OFF
REM CHPATH.BAT
IF %2!==! GOTO ERROR
PATH >RESTORE.BAT
SET M=%1
SET P=%2
IF !%2==!-DB CPSET1 %PATH%
IF !%2==!-db CPSET1 %PATH%
IF !%2==!-DE CPSET2 %PATH%
IF !%2==!-de CPSET2 %PATH%
IF !%2==!-I CPSET3 %PATH%
IF !%2==!-i CPSET3 %PATH%
SET P=
SET M=
IF !%2==!-B PATH=%1;%PATH%
IF !%2==!-b PATH=%1;%PATH%
IF !%2==!-E PATH=%PATH%;%1
IF !%2==!-e PATH=%PATH%;%1
PATH
GOTO END
:ERROR
ECHO Current path is:
PATH
ECHO Proper syntax is:
ECHO %0 DIRECTORY [-B -E -I -DB -DE]
ECHO -B  inserts DIRECTORY at the Beginning of the PATH
ECHO -E  inserts DIRECTORY at the End of the PATH
ECHO -DB deletes from DIRECTORY to the Beginning of the PATH
ECHO -DE deletes from DIRECTORY to the End of the PATH
ECHO -I  deletes DIRECTORY from the PATH
ECHO When deleting DIRECOTRY, type DIRECTORY in ALL CAPS
:END
-------------------------------------------------------------------------------
ECHO OFF
REM CPSET1.BAT
CPSET2 %9;%8;%7;%6;%5;%4;%3;%2;%1
-------------------------------------------------------------------------------
ECHO OFF
REM CPSET2.BAT
SET PATH=
:LOOP
IF !%P%==!-DB PATH=%1;%PATH%
IF !%P%==!-db PATH=%1;%PATH%
IF !%P%==!-DE PATH=%PATH%%1;
IF !%P%==!-de PATH=%PATH%%1;
SHIFT
IF NOT !%1==! IF NOT !%1==!%M% GOTO LOOP
SET M=
SET P=
PATH
-------------------------------------------------------------------------------
ECHO OFF
REM CPSET3.BAT
SET PATH=
:LOOP
IF NOT %1==%M% PATH=%PATH%%1;
SHIFT
IF NOT !%1==! GOTO LOOP
SET M=
SET P=
PATH