Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!sun!imagen!auspyr!sci!phil From: phil@sci.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Help with directories and batch files... Message-ID: <3098@sci.UUCP> Date: Thu, 19-Mar-87 12:12:51 EST Article-I.D.: sci.3098 Posted: Thu Mar 19 12:12:51 1987 Date-Received: Sun, 22-Mar-87 16:34:15 EST Organization: Silicon Compilers Inc., San Jose, Calif. Lines: 64 In article <839@bucsb.bu.edu.UUCP>, keast@bucsb.bu.edu.UUCP (Kenneth East) 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 > [...] > >>Anybody out there have any idea how I can do this? Step one is the problem > Actually there is a very simple way to do it with I/O re-direction: > > 1) Create a file called cd.txt which contains ONLY the two letters > 'cd' followed by a space followed by a ^Z (end of file). Let's say > that we have created such a file and placed it in the > directory \batch. > > 2) You will have to place the following in a batch file which > in turn will execute your program(s). For example: > > REM place a 'cd ' in the file old_dir.bat > copy \batch\cd.txt \batch\old_dir.bat > REM append the current directory path to the same file > cd >> \batch\old_dir.bat > REM now you can change directories at will and execute programs, etc. > cd \progs\etc > foo.exe > REM to return to the original directory, just execute the batch file > REM you created above: > \batch\old_dir.bat > REM and you are back at the original directory. > > Please, no flames. I know it's inelegant, but it works fine, and I have > better things to do than writing a "real" program to do this. -- > ======================================+================================= The above approach works great but is not quite general enough. It does not handle the case where the target directory is on a different drive than the original drive. the simple fix is to add a couple more commands: after the first cd >> ... line that puts the old directory on the file add cd \ to get to the current drives root dir cd >> ... to put the drive name on the file Now when the return file is executed you will not only cd to the right directory but also change drive default back if it has been changed the rest of this text is because of the fact that my stupid mailer requires that there be more new text than included text how is that for fine programming? alas, how often does one get to have a program that enforces efficiency by insisting on more text than you need. anyone have a pointer to the great programmer in the sky who did us this favor?