Article View: comp.sys.mac
Article #16868Re: obtaining the full pathname of a file
From: Larry Rosenstein
Date: Fri, 12 Jun 1987 23:12
Date: Fri, 12 Jun 1987 23:12
140 lines
3912 bytes
3912 bytes
In article <204@drilex.UUCP> dricej@drilex.UUCP (Craig Jackson) writes:
>this. Does anyone have any working code that they code post? (C, Pascal?)
>Does MacApp provide this facility?
MacApp doesn't provide this. I wrote some code, which I have included
below. (This was taken from an early version of the StdFile MPW tool, which
comes with MPW 2.0.)
IEString is a string type that is defined in the MPW integrated environment
unit. This code doesn't check to see if your final pathname exceeds 255
characters. This code did work, but I don't guarantee that I didn't make
any mistakes while pulling it out of the program.
Larry Rosenstein
UUCP: {sun, voder, nsc, mtxinu, dual}!apple!lsr
CSNET: lsr@Apple.com
*******************************
VAR
gotHFS: BOOLEAN;
{ Setting the above variable is left as an exercise for the reader. }
{ Given a working directory refnum, return the volume refnum and dirID.
This assumes that HFS is installed on the machine. }
FUNCTION GetDirID(VAR vRefnum: INTEGER; VAR dirID: LONGINT): OSErr;
VAR pb: WDPBRec;
BEGIN
WITH pb DO
BEGIN
ioCompletion := NIL;
ioNamePtr := NIL;
ioVRefnum := vRefnum;
ioWDIndex := 0;
ioWDProcID := 0;
ioWDVRefnum := vRefnum;
END;
GetDirID := PBGetWDInfo(@pb, FALSE);
vRefnum := pb.ioWDVRefnum;
dirID := pb.ioWDDirID;
END;
{ Given a volume refnum and dirID, return name of the volume / folder. This
routine assumes that HFS is installed on the machine. }
FUNCTION DirID2Name(vRefnum: INTEGER; dirID: LONGINT;
VAR name: IEString): OSErr;
VAR pb: CInfoPBRec;
temp: Str255;
err: OSErr;
BEGIN
name := '';
err := noErr;
WITH pb DO
BEGIN
ioCompletion := NIL;
ioNamePtr := @temp;
ioVRefnum := vRefnum;
ioDrDirID := dirID;
END;
REPEAT
pb.ioFDirIndex := -1; { get info about directory ioDirID }
err := PBGetCatInfo(@pb, FALSE);
IF err = noErr THEN
BEGIN
name := Concat(temp, ':', name);
IF pb.ioDrDirID = 2 THEN { root directory }
pb.ioDrDirID := 0
ELSE
pb.ioDrDirID := pb.ioDrParID;
END;
UNTIL (err <> noErr) | (pb.ioDrDirID = 0);
DirID2Name := err;
END;
{ Given a volume or WD refnum, return name of the volume / folder.
This can be called whether or not HFS exists.
This is the primary procedure that you would call from your program. }
FUNCTION GetFolderName(vRefnum: INTEGER; VAR name: IEString): OSErr;
VAR pb: CInfoPBRec;
temp: Str255;
err: OSErr;
dirID: LONGINT;
i: INTEGER;
len: INTEGER;
BEGIN
name := '';
err := noErr;
IF gotHFS THEN { find the dirID, and get the full pathname }
BEGIN
err := GetDirID(vRefnum, dirID);
IF err = noErr THEN
GetFolderName := DirID2Name(vRefnum, dirID, name);
END
ELSE { no HFS, just get the volume name }
BEGIN
temp := '';
WITH pb DO
BEGIN
ioCompletion := NIL;
ioNamePtr := @temp;
ioVRefnum := vRefnum;
ioFDirIndex := 0;
ioDrDirID := 0;
END;
err := PBGetVInfo(@pb, FALSE);
IF err = noErr THEN
name := Concat(temp, ':');
END;
GetFolderName := err;
END;
***** END OF CODE *****
--
Larry Rosenstein
Object Specialist
Apple Computer
AppleLink: Rosenstein1
UUCP: {sun, voder, nsc, mtxinu, dual}!apple!lsr
CSNET: lsr@Apple.com
Technical Details
Message-ID:
<1022@apple.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!im4u!rutgers!ames!amdahl!nsc!voder!apple!lsrReferences:
<1345@batcomputer.tn.cornell.edu> <1007@apple.UUCP> <204@drilex.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!im4u!rutgers!ames!amdahl!nsc!voder!apple!lsr From: lsr@apple.UUCP (Larry Rosenstein) Newsgroups: comp.sys.mac Subject: Re: obtaining the full pathname of a file Message-ID: <1022@apple.UUCP> Date: Fri, 12-Jun-87 19:12:54 EDT Article-I.D.: apple.1022 Posted: Fri Jun 12 19:12:54 1987 Date-Received: Sun, 21-Jun-87 01:44:07 EDT References: <1345@batcomputer.tn.cornell.edu> <1007@apple.UUCP> <204@drilex.UUCP> Reply-To: lsr@apple.UUCP (Larry Rosenstein) Organization: Advanced Technology Group, Apple Computer Lines: 140