CompuServe Thread

#Path string from lock?

3 messages in this thread
#12597From: SyndesisJul 28, 1991 5:06 PM
Before I leave for Siggraph, I'll post a question for the gurus: Given a lock on a directory or a file, how can I reconstruct a string of its complete filename and path? Can you direct me to some source code for doing this? Does this method, if any, break under 2.0?
#12605From: Khalid AldoseriJul 28, 1991 7:54 PM
John, it's quite a trivial piece of code. If you've got the lock to a file you can find out its name by Examine()ing the lock to get the FileInfoBlock. From that, you just then move backwards towards the top of the directory tree by using ParentDir(lock), which returns a lock to the parent directory of a lock, if it exists. It can be easily implemented as a recursive piece of code. If you like I'll dump the one I use. (and it works perfectly under 2.0) Khalid.
#12622From: Bob RakoskyJul 29, 1991 12:23 AM
John, I believe there's an AmigaDOS function to do it in 2.0, but I assume you're trying to maintain pre-2.0 compatibility. The following function works reliably for me: —————————– CHAR pbuf[MAX_PATH]; CHAR * lock_to_pathstr(BPTR lok) { char buf0[MAX_PATH]; BPTR plok; int i; struct FileInfoBlock *fib; pbuf[0] = '\0'; fib = (struct FileInfoBlock *) AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR); if (!fib) { return(pbuf); } buf0[0] = '\0'; plok = lok; while (plok) /* Parent lock==0 ==> last lock was volume node */ { if (!Examine(plok,fib)) { goto outtahere; } plok = ParentDir(plok); if (!plok) { strcpy(buf0,fib->fib_FileName); strcat(buf0,":"); strcat(buf0,pbuf); strcpy(pbuf,buf0); break; /* exit loop here and only here */ } strcpy(buf0,fib->fib_FileName); strcat(buf0,"/"); strcat(buf0,pbuf); strcpy(pbuf,buf0); } i = strlen(pbuf) – 1; if (pbuf[i] == '/') { pbuf[i] = '\0'; } outtahere: if (fib) { FreeMem((char *)fib,(long)sizeof(struct FileInfoBlock)); } return(pbuf); } —————————- Hope this helps…. ….BobR