Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!decvax!tektronix!cae780!ubvax!scott From: scott@ubvax.UUCP (Scott Scheiman) Newsgroups: comp.sys.ibm.pc Subject: Re: Help with directories and batch files... Message-ID: <714@ubvax.UUCP> Date: Wed, 18-Mar-87 14:59:51 EST Article-I.D.: ubvax.714 Posted: Wed Mar 18 14:59:51 1987 Date-Received: Sat, 21-Mar-87 04:24:24 EST References: <4471@columbia.UUCP> Organization: Ungermann-Bass, Inc., Santa Clara, CA Lines: 70 In article <4471@columbia.UUCP>, m-liu@flims (Micky Liu) writes: > > I am trying to use a batch file to: > > 1) save the current directory > 2) goto another directory > 3) execute some program > 4) return to saved directory This may be a little kludgey for you, but I've been able to do this using just batch files (hack, hack!). Here's my PUSHD.BAT: echo off copy c:\bat\pushd.dat d:\~push.bat >nul: cd >>d:\~push.bat echo set ~PUSH=%%PUSH%% %%~PUSH%%>>d:\~push.bat echo set PUSH=>>d:\~push.bat if not "%1"=="" echo %1 %2 %3 %4 %5 %6 %7 %8 %9 >>d:\~push.bat d:\~push where the file pushd.dat contains: echo off set PUSH= What all this does is create a temporary batch file ~push.bat in a work directory (here it's d:) which places your current directory name into the environment string PUSH, then moves it to the front of a string of saved directories in the environment string ~PUSH (and removes PUSH). If pushd was called with arguments, they are placed in ~push.bat to be executed. Finally, pushd.bat chains to the newly-created ~push.bat. What this relies on is (1) batch-file chaining and (2) the %-notation substitution into batch files from the environment which was much discussed on the net a few weeks ago. In order to do the four steps you wanted, chaining is necessary: your original command (presumably a batch file) chains to pushd.bat, then ~push.bat, which then runs another batch file (unless you modify my stuff to do it) to change the directory, run your command, and finally chain to popd.bat. Regarding the % substitutions, note that the %'s are doubled to defer the substitution until ~push.bat runs. In order for this to work, pushd.dat must NOT end in CR-LF. I don't know of any editors which allow this fully, so I've used the Norton Utility (or DEBUG) to change the CR-LF to blanks. For completeness, here's my popd.bat. I'll leave it's analysis as an exercise for you readers: echo off if exist d:\~push.bat erase d:\~push.bat if "%1"=="" c:\bat\~popd %~PUSH% chdir %~PUSH% if "%1"=="/" set ~PUSH= if "%1"=="/" shift if "%1"=="." shift ; %1 %2 %3 %4 %5 %6 %7 %8 %9 where ~popd.bat is: echo off if "%1"=="" goto finis chdir %1 :finis set ~PUSH= if not "%2"=="" set ~PUSH=%2 %3 %4 %5 %6 %7 %8 %9 -- "Ribbit!" Scott (Beam Me Up, Scotty!) Scheiman Industrial Networking Inc. `/\/@\/@\/\ ..decvax!amd!ubvax!scott 3990 Freedom Circle _\ \ - / /_ (408) 562-5572 Santa Clara, CA 95050