gay%CLSEPF51.BITNET@cunyvm.cuny.edu (David Gay) (07/01/88)
Jim Blandy writes: > >(simple question I feel stupid about asking) > > How can I set my current directory? I could probably munge > around with AmoebaDOS's data structures, but what's the > system-approved way of doing it? > Try BPTR dir; /* ... */ CurrentDir(dir = CurrentDir(0L)); dir will then be a lock on the current directory (To those that know: the use of 0 won't cause a demand for the boot disk, will it ?). To actually get the path, you then have to fool around with this. Here's a little code to do so: char *getpath(to, l) register char *to; register BPTR l; { register BPTR tl; register int notfirst = FALSE; register struct FileInfoBlock *fib = (struct FileInfoBlock *)AllocMem(sizeof( struct FileInfoBlock), 0); if (!fib) return(NULL); to[0] = '\0'; do { if (!Examine(l, fib)) return(NULL); if (fib->fib_DirEntryType > 0) strins(to, "/"); if (fib->fib_FileName[0] == '\0') strins(to, "RAM"); /* Special case ... * / else strins(to, fib->fib_FileName); tl = l; l = ParentDir(l); if (notfirst) UnLock(tl); notfirst = TRUE; } while (l); *(strchr(to, '/')) = ':'; FreeMem((char *)fib, sizeof(struct FileInfoBlock)); return(to); } This compiles under Lattice C v4.01, "l" is the lock for which you want the path, "to" points to a buffer "big enough" to accept the path (Yes, it would be nicer if there was a maximum length argument). If there's a bug in this, that's one more to add to the list of bugs in the hp11 ... (A new version coming from the moderators one day ...). >-- >Jim Blandy - blandy@crnlcs.bitnet >"insects were insects when man was just a burbling whatisit." - archie > David Gay Studying Computer Science at the EPFL, Ecole Polytechnique Federale de Lausanne, Switzerland. GAY@ELDE.EPFL.CH, or GAY@CLSEPF51.bitnet (till August) P.S. I hope this wasn't in comp.sys.amiga.tech. I receive all this through amiga-relay, and I don't know if I receive comp.sys.amiga alone or not (some of the messages I receive suggest that they were posted to .tech, now and again I receive something in duplicate (cross-posted ?), but as I don't get a newsgroup line in the messages ...). Anybody care to enlighten me ?