[comp.sys.ibm.pc] How do I remember my current directory?

tom@ismdqa.intel.com (Tom Soukup ~) (02/03/89)

Hi All,

Is there any way in MS-DOS to save the current working directory in a variable?
I need to change directories in a .bat file and would like to be able to
return to where I started when finished.

Thanks for the help
Tom

________________________________________________________________________________
DISCLAMER:  Intel doesn't agree with much of anything that I say.

jborza%burgundy@Sun.COM (Jim_Borza) (02/04/89)

In article <3536@mipos3.intel.com>, tom@ismdqa.intel.com (Tom Soukup ~) writes:
> 
> Hi All,
> 
> Is there any way in MS-DOS to save the current working directory in a 
> variable?
> I need to change directories in a .bat file and would like to be able to
> return to where I started when finished.
> 
> Thanks for the help
> Tom
> DISCLAMER:  Intel doesn't agree with much of anything that I say.

PC Magazine published a pair of utilities called PUSHDIR and POPDIR which
do exactly that.  It's been around for several years so they should be
on a lot of BBSs, or can be gotten from their own services (IRS and 
PC MagNet).
Jim Borza - Sun Microsystems
Disclaimer?  Sure, why not?

marc@dbase.UUCP (Marc Schifer) (02/04/89)

In article <3536@mipos3.intel.com>, tom@ismdqa.intel.com (Tom Soukup ~) writes:
> 
> Is there any way in MS-DOS to save the current working directory in a variable?
> I need to change directories in a .bat file and would like to be able to
> return to where I started when finished.
> 
    There is a little trick you can do to save your current directory into
    a enviorment variable.  
      1st.  Create a text file as follows
           COPY CON SETTEXT.TXT <CR>
	   set STARTDIR=^Z

	   Note that you MUST be shure to end the file with a control Z before
	   typing a Carriage Return.  If you hit the Enter key before the 
	   Cntrl-Z this will not work.
      2nd  In the batch file do the following sequenc of commands at the 
	   start of the file
	   CD >DIROUT.TXT
	   COPY SETTEXT.TXT+DIROUT.TXT SETDIR.BAT
	   CALL SETDIR

	   REM You now have a Enviorment Variable called STARTDIR that
	   REM is equal to you starting directory
	   REM  Now Place the rest of your batch file after and end it
	   REM with the following command to return to the starting dir.

	   CD %STARTDIR%

	   REM of course this only works if you don' change drives.
	   REM but a simialr scheme could be used to handle that as well.

	    REM  Note the Call command was implemneted in DOS 3.3 If you are
	   using a Older version of DOS you will  have to execute the bat
	   file SETDIR.BAT by invoking a second command processor.
	   (See you dos manual for command.com option on how to do this.)
  
	    I hope this helps.


	    /marc/

	    -------------------
	    Standard Discalimer implied
	    (i.e. ThisAin'tNobodysOppionButMyOwn,SoThere!)