Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!thumper!ulysses!gamma!mibte!fmsrl7!eecae!nancy!mailrus!nrl-cmf!ames!umd5!mimsy!oddjob!uwvax!puff!avery From: avery@puff.cs.wisc.edu (Aaron Avery) Newsgroups: comp.sys.amiga.tech Subject: Re: Changing Directories Message-ID: <1554@puff.cs.wisc.edu> Date: 7 Apr 88 20:23:29 GMT References: <8804060734.AA13918@jade.berkeley.edu> Reply-To: avery@puff.WISC.EDU (Aaron Avery) Organization: U of Wisconsin CS Dept Lines: 41 In article <8804060734.AA13918@jade.berkeley.edu> SLMYQ@USU.BITNET writes: >Here are some hints for changing the current directory in a program. Good ideas, thanks for posting them. >Next suggestion. Unless you are writing a CD program, you really should >save and restore the old current directory, so if you start a program from Very true. Here's what I do: At the beginning of my program, I do: curdir = DupLock(FindTask(NULL)->pr_CurrentDir); firstdir = CurrentDir(curdir); So now I have firstdir available to CurrentDir to at the end of my program. Now, since _I_ allocated curdir, I can use: curdir = newdir; UnLock(CurrentDir(curdir)); to move to a new directory. This is, of course, after checking that newdir is valid and is a directory. At the end of my program I just: UnLock(CurrentDir(firstdir)); and I'm back! One note: curdir = Lock("", ACCESS_READ); can be used in place of the above DupLock(). >Now if you're wondering why the current directory could possibly be zero, >it's because of one of those weird things in AmigaDOS. When a process is >first created, its pr_CurrentDir is set to zero, rather than some specific >lock. With the BCPL commands, this zero lock "assumes" the SYS: directory. Are you sure about this? When you 'run ', the newly created process has whatever current directory the shell it was invoked from has. But I do believe that if you never switched directories in your original shell, what you said above is true. -- Aaron Avery (avery@puff.cs.wisc.edu) ({seismo,caip,allegra,harvard,rutgers,ihnp4}!uwvax!puff!avery)