patrick@crcmar.crc.uucp (Andrew Patrick) (06/21/88)
There is probably a simple answer to this question, but here it is anyway: How can I add directories to my PATH specification on the fly? I want to leave the path as it is and simply add directories on the end. I don't want to edit AUTOEXEC.BAT and reboot, and I don't want the changes to be permanent. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Andrew Patrick, Ph.D. Communications Research Center, Ottawa, CANADA (613) 990-4675 SMARTMAIL: patrick@crcmar.uucp UUCP: ...utzoo!dciem!nrcaer!crcmar!patrick BITNET: patrick%crcmar@UTORGPU ARPA: dgbt@ncs-dre.arpa "Home of the world's first microwave airplane!" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Devin_E_Ben-Hur@cup.portal.com (06/25/88)
To add additional directories to your path, make a batch file (ADDPATH.BAT): PATH %PATH%;%1 then invoke: ADDPATH <new-path-dir>
jamesd@lakesys.UUCP (James Dicke) (06/25/88)
In article <688@crcmar.crc.uucp> patrick@crcmar.crc.uucp (Andrew Patrick) writes: >There is probably a simple answer to this question, but here it is >anyway: > >How can I add directories to my PATH specification on the fly? > >I want to leave the path as it is and simply add directories on the >end. I don't want to edit AUTOEXEC.BAT and reboot, and I don't want >the changes to be permanent. > I suppose there are two ways to go about this. 1) In DOS 3.0 > there you may use "SET PATH=%PATH%" followed by the path to add. This will add the new path permanently. This command also ONLY works in a batch file. 2) There are a few public domain packages that allow you to actually EDIT your path setting. These are nice but have some compatibility problem. I have one here called "Edit Environment" by Bill Bovee. Of course none of these methods work in a shell. jamesd@lakesys.UUCP Call the infamous City of Aldimar adventure system @ (414) 527-4779 Not a BBS- but an ongoing adventure GAME in a woundrous world. (Spells, Monsters, Combat, Dungeons, Equipment, Treasures, Term-emu, & more)
tim@j.cc.purdue.edu (Timothy Lange) (06/25/88)
Here is what I do when I want to add another drive/directory to my path. Create a batch file with this line: path=%path%;%1 I call mine 'setpath', to use it just type 'setpath \newpath', which tacks '\newpath' to the end of the path list. Be careful when typing the above, the ';' is important! Tim. -- Timothy Lange / Purdue University Computing Center / Mathematical Sciences Bldg. West Lafayette, IN 47907 / 317-494-1787 / tim@j.cc.purdue.edu / CIS 75410,525
richardh@killer.UUCP (Richard Hargrove) (06/25/88)
In article <688@crcmar.crc.uucp>, patrick@crcmar.crc.uucp (Andrew Patrick) writes: > How can I add directories to my PATH specification on the fly? > > I want to leave the path as it is and simply add directories on the > end. I don't want to edit AUTOEXEC.BAT and reboot, and I don't want > the changes to be permanent. The simplest way to do this is to create two .BAT files named, say, PA.BAT and ADDPA.bat. Their contents: ADDPA.BAT: PATH %PATH%;%1 PA.BAT: PATH {the same path definition you have in command.com} To add a PATH node, you enter ADDPA {pathnode} To restore the original PATH, you enter PA OF course, if you use some sort of shell or interface enhancement utility like [P]CED, there may be other ways to accomplish the same thing without eating up disk space. richard hargrove ...!{ihnp4 | codas | cbosgd}!killer!richardh --------------------------------------------
emb978@leah.Albany.Edu (Eric M. Boehm) (06/25/88)
In article <688@crcmar.crc.uucp>, patrick@crcmar.crc.uucp (Andrew Patrick) writes: > How can I add directories to my PATH specification on the fly? > > I want to leave the path as it is and simply add directories on the > end. I don't want to edit AUTOEXEC.BAT and reboot, and I don't want > the changes to be permanent. I have a set of batch files I picked up from PC Magazine that lets you add directories to the beginning or end of the path variable, allows you to delete a single directory, or delete forward and backward of a single directory (including the directory). The batch file also saves the path as it was before the current invocation so you can restore the path setting . However, if you added two directories in two separate calls, it would only save the most recent path. If you want the change to be temporary, it is easiest to invoke a shell (type "command" at the prompt). Any changes you make will be lost when you "exit". If this is of enough interest, I will post the files -- 4 batch files, less than 1K total (but where? comp.binaries.ibm.pc? comp.sys.ibm.pc?) Eric M. Boehm EMB978@ALBNY1VX.BITNET EMB978@LEAH.ALBANY.EDU
ljz@fxgrp.UUCP (Lloyd Zusman) (06/26/88)
In article <6836@cup.portal.com> Devin_E_Ben-Hur@cup.portal.com writes:
To add additional directories to your path, make a batch file (ADDPATH.BAT):
PATH %PATH%;%1
then invoke:
ADDPATH <new-path-dir>
You can go a bit further with this. I seem to recall that the original
poster also asked for a way to quickly revert back to the old path.
Here are a couple of .BAT files that should do the job:
First file, ADDPATH.BAT:
set OLD_PATH=%PATH%
:back
if .%1==. goto done
set PATH=%PATH%;%1
shift
goto back
:done
Second file, OLDPATH.BAT:
if .%OLD_PATH%==. goto done
set PATH=%OLD_PATH%
set OLD_PATH=
:done
You can then type
ADDPATH foo bar baz
to add the directories 'foo', 'bar', and 'baz' to your path.
Typing
OLDPATH
will restore your old path.
If you are running under DOS 3.30 or above, you can call these from within
another batch file as follows:
call ADDPATH mydir
rem do whatever you want
rem ...
call OLDPATH
--
Lloyd Zusman UUCP: ...!ames!fxgrp!ljz
Master Byte Software Internet: ljz%fx.com@ames.arc.nasa.gov
Los Gatos, California or try: fxgrp!ljz@ames.arc.nasa.gov
"We take things well in hand."
swillett@violet.berkeley.edu (06/26/88)
My approach is to create an environment variable called NPATH in the autoexec.bat file: set NPATH=%PATH% after I have created my default path. I also have two batch files which I keep in a directory which is in my default path (UTIL): NSAVPATH.BAT SET NPATH=%PATH% PATH = %PATH%;%1 OLDPATH.BAT PATH=%NPATH% I use the first as NSAVPATH d:\workdir to create a new path while saving my old path and then I recall my old path OLDPATH You can still use PATH to create an entirely new path and then use OLDPATH to restore the last path you saved to NPATH (like your default if you have not used NSAVPATH.
hwfe@ur-tut (Harlan Feinstein) (06/27/88)
I'm well aware that this topic has been kicked around, and I hereby request that any answers to this question be _emailed_ to me rather than discussed again. The question: "how do I enlarge the environment space?" There; I said it. I'd appreciate information on this. :-) --Harlan hwfe@tut.cc.rochester.edu hwfeccss@uorvm.bitnet
bicker@hoqax.UUCP (The Resource, Poet of Quality) (06/27/88)
In article <688@crcmar.crc.uucp>, patrick@crcmar.crc.uucp (Andrew Patrick) writes: > How can I add directories to my PATH specification on the fly? With EE2, environmental editor, a public domain program available widely. I'm sure it is in the various archives around the net and many BBSs. -- /kohn/brian.c AT&T Bell Laboratories Semantic Engineering Center The Resource, Poet of Quality ...ihnp4!hoqam!bicker (201) 949-5850 "It is useless for sheep to pass resolutions in favor of vegetarianism while wolves remain of a different opinion." - Wm. Ralph Inge, D.D.
sme@computing-maths.cardiff.ac.uk (Simon Elliott) (07/06/88)
I have a small utility which reads the current PATH, edits it and outputs to stdout. In conjunction with a batch file it allows me to insert an element before the current path, append an element after the current path, insert an element at position N in the current path, and delete an element from the current path. e.g. C>pathedit -2 C:\sme\bin PATH=C:\BATCH;C:\SME\BIN;C:\DOS;C:\BIN puts C:\sme\bin into position 2 in the path and eliminates it elsewhere in the path (My pathedit.bat always reports the resulting PATH) ... similarly with options -a -i -d I can post the batch and C sources if folks are interested. Simon Elliott Microcomputer Support University College Cardiff Computer Centre, Cardiff, Wales ...!mcvax!ukc!cf-cm!sme
halff@nprdc.arpa (Henry Halff) (07/06/88)
In article <688@crcmar.crc.uucp> patrick@crcmar.crc.uucp (Andrew Patrick) writes: >There is probably a simple answer to this question, but here it is >anyway: > >How can I add directories to my PATH specification on the fly? > >I want to leave the path as it is and simply add directories on the >end. I don't want to edit AUTOEXEC.BAT and reboot, and I don't want >the changes to be permanent. Here are two simple batch programs that do what you want PATHPLUS.BAT set oldpath=%path% path %path%;%1 PATHREST.BAT set path=%oldpath% HH
lowey@damask.UUCP (Kevin Lowey) (07/07/88)
In article <6836@cup.portal.com>, Devin_E_Ben-Hur@cup.portal.com writes: > To add additional directories to your path, make a batch file (ADDPATH.BAT): > PATH %PATH%;%1 > > then invoke: > ADDPATH <new-path-dir> Be aware that version 2.00 (I think) of MS-DOS has a bug in that everything after the %PATH% is ignored (or any environment variable referenced this way). The solution is to change the path command to: PATH %1;%PATH% ______________________________________________________________________________ | Kevin Lowey |The above is the personal opinion of Kevin | | University of Saskatchewan |Lowey. It does not reflect the position of| | Computing Services |the University of Saskatchewan in any way. | | SaskTel: (306) 966-4826 | | | Bitnet:LOWEY@SASK. (preferred) |I am in no way affiliated with any of the | | UUCP: ihnp4!damask!lowey.uucp |above mentioned companies other than U of S| |________________________________|___________________________________________|
sme@computing-maths.cardiff.ac.uk (Simon Elliott) (07/11/88)
Here is pathed.c, containing instructions for its surrounding batch files for various versions of DOS. I compiled it with Turbo C v1.0. It uses strtok, which some compilers' libraries don't have. ------------------------8x----------------------8x------------------------ /* * pathed.c - core of path editor * * Written by Simon Elliott (...!mcvax!ukc!cf-cm!sme). * Version 1.0 10/11/87. * * As you will see from the usage message, this claims to be PATHEDIT. * Actually, this program is called from within a batch file, and * should be called PATHED, or something. I keep PATHED.EXE _and_ * PATHEDIT.BAT in my \BATCH directory, which is _always_ in my * PATH. (PATHED.EXE is the only non-.BAT in \BATCH) * * Here is PATHEDIT.BAT for Dos < 3.30: * echo off * pathed %1 %2 >\$$$.bat * if not errorlevel 1 \$$$ * * and for Dos >= 3.30: * @echo off * pathed %1 %2 >$$$.bat * if not errorlevel 1 call $$$.bat * del $$$.bat >nul * * usage: * pathedit -a d:\path appends to current path * pathedit -d d:\path deletes d:\path from current path * pathedit -i d:\path inserts d:\path before current path * pathedit -3 d:\path adds/moves d:\path to 3rd place in path */ #include <stdio.h> char pathbuffer[129]; /* delete() builds path command here */ char *pathcommand = "path "; char *getenv(), *strcpy(), *strchr(), *strtok(); void usage(), pathcmd2(), delete(), moveto(); main(ac, av) int ac; char *av[]; { register char *current; if (ac < 3 || *av[1] != '-' && *av[1] != '/') usage(); current = getenv("PATH"); strupr(av[2]); switch (av[1][1]) { case 'A': case 'a': /* append */ if (current) pathcmd2(current, av[2]); else pathcmd2(av[2], ""); break; case 'D': case 'd': /* delete */ if (current) delete(av[2], current); break; case 'I': case 'i': /* insert */ if (current) pathcmd2(av[2], current); else pathcmd2(av[2], ""); break; default: /* numeric position or bad option */ if (!isnumber(++av[1])) usage(); /* first delete any of the target component */ if (current) { strcpy(pathbuffer, current); delete(av[2], current); } else pathbuffer[0] = '\0'; /* pathbuffer contains the path after deletions */ moveto(atoi(av[1]), av[2], pathbuffer); } /* make batch report what the path is now */ fputs("path\n", stdout); exit(0); } void usage() { fputs("usage: pathedit [-a] [-d] [-i] [-N] d:\\path\n", stderr); exit(1); } /* * pathcmd2() - output a path command with one or possibly two strings. */ void pathcmd2(first, second) char *first, *second; { fputs(pathcommand, stdout); fputs(first, stdout); if (*second) { putchar(';'); fputs(second, stdout); } putchar('\n'); } /* * delete() - delete occurences of deletion from well formed PATH string * pointed to by source. */ void delete(deletion, source) char *deletion, *source; { register char *dest; register int first; char *component; first = 1; dest = pathbuffer; /* look for ';' separator until end of string */ component = strtok(source, ";"); while (component != NULL) { if (strcmp(deletion, component)) { /* no match - copy component to dest */ if (!first) *dest++ = ';'; strcpy(dest, component); dest = strchr(dest, '\0'); first = 0; } /* advance the component of the PATH */ component = strtok(NULL, ";"); } if (first) { fputs("set PATH=", stdout); pathbuffer[0] = '\0'; } else { fputs(pathcommand, stdout); fputs(pathbuffer, stdout); } putchar('\n'); } /* * moveto() - move PATH component insertion to position posn in well-formed * PATH string pointed to by source. * we assume that insertion has been deleted already in the source string. */ void moveto(posn, insertion, source) register int posn; /* desired position of insertion in source */ char *insertion, *source; { register int curposn; int needsemi; fputs(pathcommand, stdout); curposn = 1; /* number positions from 1 */ needsemi = 0; /* start off not needing a semicolon */ while (curposn < posn && *source) { if (';' == *source) { ++curposn; needsemi = 0; } else needsemi = 1; putchar(*source++); } /* need this kludge because we could be at 1st or last position */ if (needsemi) putchar(';'); fputs(insertion, stdout); if (*source) { /* write out rest of source (if any) */ putchar(';'); fputs(source, stdout); } putchar('\n'); } isnumber(str) char *str; { char c; while (c = *str++) /* assign */ if (c < '0' || c > '9') return 0; return 1; } ------------------------8x----------------------8x------------------------ If you find this half as useful as I do, then just remember - I'm finding it twice as useful as you are, so there! Enjoy! -- Simon Elliott Microcomputer Support University College Cardiff Computer Centre, Cardiff, Wales ...!mcvax!ukc!cf-cm!sme