Article View: comp.sys.ibm.pc
Article #25903Re: IBM DOS System Variables
From: Rodrigo Murillo
Date: Fri, 25 Mar 1988 16:53
Date: Fri, 25 Mar 1988 16:53
53 lines
2658 bytes
2658 bytes
In <1286@silver.bacs.indiana.edu> creps@silver.UUCP (Steve Creps) writes
>In article <1501@ur-tut.UUCP> nsto@ur-tut (Natalie Stone) writes:
>>Is there a way to assign a variable from within a batch file to be
>>equal to the current directory name so it can then be used in
>>the batch file.
>
> Not really with just MS-DOS batch files.
> [ references to pushdir/popdir and sugestions to try a high level language]
Who said it could not be done??
Yes folks, batch files are fun! I devised a way to store the current
directory and return to it from a DOS batch file. It isn't particularly
pretty, but it is handy if you don't have things like popdir/pushdir yet.
It also uses some handy features of DOS like redirection and file
concats, and redirection to the NUL: device.
Redirection of the CD command to a text file is the key. CD by itself
returns the current directory. That file is then appended to a 3 character
text file that has the string "CD " in it, WITHOUT a return. The
resultant file is given a batch extention, and then run to return to
the directory.
create the DOS command file somewhere handy, (no CR)
C:\>copy con \tools\cd.dos
cd ^Z
1 File(s) copied
Here is a batch file that goes to the root, then returns
to whatever directory it started in.
==> foobar.bat
echo off
REM * Redirect the output of cd to a temp file
cd >\tools\cd.txt
cd\
REM * Verify thet we are now in the root
echo Hello from the root!
cd
pause
REM * Create the go.bat file that will exec the cd\[old directory]
copy \tools\cd.dos + \tools\cd.txt go.bat >nul:
REM * Call the batch file, but return back here.
REM * DOS 3.3 users can CALL go.
command/c go
REM * Drop out of the batch file here, or add more features.
--
_______________________________________________________________________________
Rodrigo Murillo, University of Colorado - Boulder (303) 761-0410
murillo@boulder.colorado.edu | ..{hao|nbires}!boulder!murillo
( Machines have less problems. I'd like to be a machine. -- Andy Warhol )
Technical Details
Message-ID:
<5074@sigi.Colorado.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!rochester!ur-tut!sunybcs!boulder!murilloReferences:
<1501@ur-tut.UUCP> <1286@silver.bacs.indiana.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!rochester!ur-tut!sunybcs!boulder!murillo From: murillo@sigi.Colorado.EDU (Rodrigo Murillo) Newsgroups: comp.sys.ibm.pc Subject: Re: IBM DOS System Variables Message-ID: <5074@sigi.Colorado.EDU> Date: 25 Mar 88 16:53:21 GMT References: <1501@ur-tut.UUCP> <1286@silver.bacs.indiana.edu> Reply-To: murillo@boulder.Colorado.EDU (Rodrigo Murillo) Distribution: na Organization: University of Colorado, Boulder Lines: 53 Keywords: IBM, DOS, Directories, batch files