[comp.sys.mac.programmer] Ref numbers to pathnames??

jmh@utacs.UTA.FI (Matti Heimonen) (08/29/88)

Sorry, if I am asking silly questions, but I still would like to know
how can I get the full pathname of a file that has been selected using
SFGetFile or SFPutFile.  Yes, I can create and open the files without 
the pathnames, but it would be informative to the user...  Thanks.

Juha-Matti Heimonen                    jmh@utacs.UUCP

bob@eecs.nwu.edu (Bob Hablutzel) (08/31/88)

> Sorry, if I am asking silly questions, but I still would like to know
> how can I get the full pathname of a file that has been selected using
> SFGetFile or SFPutFile.  Yes, I can create and open the files without 
> the pathnames, but it would be informative to the user...  Thanks.

Not a silly question. What you are really asking is how to get the
full path name for a folder, given the vRefNum (in reality, a WDRefNum)
for a volume (folder), how does one find the complete path name for the
folder.

The answer is to use successive calls to _GetCatInfo. However, to use
_GetCatInfo, you need, not the vRefNum (WDRefNum) for the volume (folder),
but the vRefNum (real vRefNum) and DirID for the volume and folder,
respectively. Clear? I should hope not.

What SFGet/PutFile returns to you is a working directory reference number.
This reference number specifies a structure in memory which in turn
specifies the volume reference number (vRefNum) and unique folder
identification (DirID). Often under HFS what you think is a vRefNum is
in reality a WDRefNum ashamed of its heritage and attempting to hide.

There is a call (_GetWDInfo) which gives the third degree to WDRefNums,
forcing them to tell you the real vRefNum and the DirID that they have
been hiding. Once you have that information, _GetCatInfo (which expects
vRefNums and DirIDs and can't really be bothered with these plebian
wdRefNums) will happily tell you the name of the folder. Moreover, it
graciously gives you the parent folder of the folder (in ioDrParID) so
you can continue up the folder path.

If this makes your head spin (and it should, HFS is in reality a Illuminati
plot) I can provide for you a routine to translate WDRefNums (from
SFGetFile, which is where this started, remember?) into ASCII strings.
All I require is that you have MPW, something that will read MPW, or an
assembler. Drop me a note, and I'll pass it along.

> Juha-Matti Heimonen                    jmh@utacs.UUCP

Bob Hablutzel		BOB@NUACC.ACNS.NWU.EDU

gz@spt.entity.com (Gail Zacharias) (08/31/88)

In article <553@utacs.UTA.FI> jmh@utacs.UUCP (Juha-Matti Heimonen) writes:
>Sorry, if I am asking silly questions, but I still would like to know
>how can I get the full pathname of a file that has been selected using
>SFGetFile or SFPutFile.

Ok, here's how I do it:

(defun full-directory-name (vrefnum &optional (dirid 0))
  (rlet ((pb :CinfoPB) (name (:string 255)))
    (rset pb CinfoPB.ioFileName name)
    (rset pb CinfoPB.ioVRefNum vrefnum)
    (rset pb CinfoPB.ioDrDirID dirid)
    (rset pb CinfoPB.ioFDirIndex -1)
    (do ((dir "" (concatenate 'string (%get-string name) ":" dir)))
        ((not (zerop (_GetCatInfo :a0 pb :d0))) dir)
      (rset pb CinfoPB.ioDrDirID (rref pb CinfoPB.ioDrParID)))))

Hope this helps :-)

--
gz@entity.com					...!mit-eddie!spt!gz
	 Now let's all repeat the non-conformist oath.