Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!husc6!unix!mxmora From: mxmora@unix.SRI.COM (Matt Mora) Newsgroups: comp.sys.mac.programmer Subject: Re: SFReply.vRefNum -> PathName Keywords: pathnames Message-ID: <9019@unix.SRI.COM> Date: 9 Feb 90 17:44:12 GMT References: <11377@attctc.Dallas.TX.US> Reply-To: mxmora@unix.UUCP (Matt Mora) Organization: SRI International, Menlo Park, CA Lines: 128 In article <11377@attctc.Dallas.TX.US> torch@attctc.Dallas.TX.US (Jay Finger) writes: >I'm need a routine that will convert the volume reference number from SFGetFile >into a pathnam. I assumed that I'd need to convert the working directory >id into a directory id and then use something like GetCatInfo to get >directory names while tracing back to the root. >Jay Finger, >{ames,mit-eddie}!attctc!torch >ames!torch@attctc Here is some routines from Apple's Source Code Examples. This is from their Stanadrd file package. It is available via FTP from apple.com (** PathNameFromDirID ****************************************************) (* (* Given a DirID and real vRefnum, this routine will create and return the (* full pathname that corresponds to it. It does this by calling PBGetCatInfo (* for the given directory, and finding out its name and the DirID of its (* parent. It the performs the same operation on the parent, sticking ITS (* name onto the beginning of the first directory. This whole process is (* carried out until we have processed the root directory (identified with (* a DirID of 2. (* (* NOTE: This routine is now A/UX friendly. A/UX likes sub-directories (* separated by slashes in a pathname. This routine automatically (* uses colons or slashes as separators based on the value of the (* global gHasAUX. This global must be initialized correctly for (* this routine to do its thing. However, because of this dependancy (* on the idiosyncracies of file systems, generating full pathnames (* for other than display purposes is discouraged; it's changed in (* the past when A/UX was implemented, and it may change again in (* the future it support for other file systems such as ProDOS, (* MS-DOS, or OS/2 are added. (* (**************************************************************************) FUNCTION PathNameFromDirID (DirID:longint; vRefnum:integer):str255; VAR Block : CInfoPBRec; directoryName, FullPathName : str255; BEGIN FullPathName := ''; WITH block DO BEGIN ioNamePtr := @directoryName; ioDrParID := DirId; END; REPEAT WITH block DO BEGIN ioVRefNum := vRefNum; ioFDirIndex := -1; ioDrDirID := block.ioDrParID; END; err := PBGetCatInfo(@Block,FALSE); IF haveAUX THEN BEGIN IF directoryName[1] <> '/' THEN BEGIN { If this isn't root (i.e. "/"), append a slash ('/') } directoryName := concat(directoryName, '/'); END; END ELSE BEGIN directoryName := concat(directoryName,':'); END; fullPathName := concat(directoryName,fullPathName); UNTIL (block.ioDrDirID = 2); PathNameFromDirID := fullPathName; END; (** PathNameFromWD **********************************************) (* (* Given an HFS working directory, this routine returns the full pathname (* that corresponds to it. It does this by calling PBGetWDInfo to get the (* VRefNum and DirID of the real directory. It then calls PathNameFromDirID, (* and returns its result. (* (**************************************************************************) FUNCTION PathNameFromWD(vRefNum:longint):str255; VAR myBlock : WDPBRec; BEGIN { { PBGetWDInfo has a bug under A/UX 1.1. If vRefNum is a real vRefNum { and not a wdRefNum, then it returns garbage. Since A/UX has only 1 { volume (in the Macintosh sense) and only 1 root directory, this can { occur only when a file has been selected in the root directory (/). { So we look for this and hardcode the DirID and vRefNum. } IF (haveAUX) AND (vRefNum = -1) THEN BEGIN PathNameFromWD := PathNameFromDirID(2,-1); END ELSE BEGIN WITH myBlock DO BEGIN ioNamePtr := NIL; ioVRefNum := vRefNum; ioWDIndex := 0; ioWDProcID := 0; END; { Change the Working Directory number in vRefnum into a real vRefnum } { and DirID. The real vRefnum is returned in ioVRefnum, and the real } { DirID is returned in ioWDDirID. } err := PBGetWDInfo(@myBlock,FALSE); WITH myBlock DO PathNameFromWD := PathNameFromDirID(ioWDDirID,ioWDVRefnum) END; END; -- ___________________________________________________________ Matthew Mora SRI International mxmora@unix.sri.com ___________________________________________________________