Path: utzoo!mnetor!uunet!husc6!bbn!rochester!pt.cs.cmu.edu!cadre!km From: km@cadre.dsl.PITTSBURGH.EDU (Ken Mitchum) Newsgroups: comp.sys.mac.programmer Subject: Re: Full path name of a file Message-ID: <1173@cadre.dsl.PITTSBURGH.EDU> Date: 6 May 88 23:34:14 GMT References: <2532@chalmers.UUCP> Reply-To: km@cadre.dsl.pittsburgh.edu.UUCP (Ken Mitchum) Organization: Decision Systems Lab., Univ. of Pittsburgh, PA. Lines: 62 In article <2532@chalmers.UUCP> olausson@chalmers.UUCP (Stefan Olausson) writes: >Given the information in a SFReply, how do I construct the full path name >of a file (as a string), i e "disk:dir1:dir2:...:filename" ? Be certain that you understand the difference between "working directory reference numbers", which SFReply returns, and directory ID numbers, which you will use to find the path name. (I only had to read the file manager chapter in Inside Mac Volume IV about ten times before understanding this!). Basically, you want to know the "real" volume (NOT the working directory reference number) and the "real" directory ID, which are two different things, neither of which being the working directory reference number. While you can take the "working directory reference number" from the SFReply structure and convert it into both volume and directory ID numbers, it is easier to take advantage of two global variables, CurDirStore and SFSaveDisk (see insert on page 72 of Inside Macintosh Vol IV). After any of the SF routines, these global variables are set as follows, REGARDLESS OF WHETHER THE USER CHOSE A FILE OR CANCELLED: CurDirStore = directoryID (long int) SFSaveDisk = 0 - volume (int) Thus, if the user changed directories but cancelled the operation, the above variables are set the way the user left them (to the new directory). It is convenient to keep track of these separately. The following code from MacJove shows a simple way to recover the path using these. In this case, the current directory is stored in cur_dir and current volume in cur_vol, which are set elsewhere (cur_dir - CurDirStore; cur_vol = 0 - SFSaveDisk. (This routine returns a "unix-style" path rather than a Mac-style path, using "/"). char *getwd() { DirInfo d; static char ret[255]; char nm[50], tmp[255]; ret[0] = '\0'; d.ioDrDirID = cur_dir; for(;;) { d.ioCompletion = 0; d.ioNamePtr = (StringPtr) nm; d.ioVRefNum = cur_vol; d.ioFDirIndex = -1; PBGetCatInfo(&d,0); if(d.ioResult != noErr) return(0); PtoCstr((char *) nm); strcpy(tmp,ret); strcpy(ret,"/"); strcat(ret,nm); strcat(ret,tmp); if(d.ioDrDirID == 2) break; /* home directory */ d.ioDrDirID = d.ioDrParID; } return(ret); } -Ken Mitchum Decision Systems Laboratories University of Pittsburgh km@cadre.dsl.pittsburgh.edu