tim@hoptoad.uucp (Tim Maroney) (01/17/91)
In article <20891@netcom.UUCP> rodent@netcom.UUCP (Ben Discoe) writes: >We're using Aztec (since the other compilers couldn't handle large data >model). We're trying to read the contents of directories other than the >current one. It seems that functions like PBGetCatInfo and PBGetWDInfo >require knowing the complete path name, which of course is unknown >without using some other function. > >Whenever we try PBGetCatInfo, it always returns the paramBlock of the >*root* directory. What's going on here? > >Does anyone know the right way to do this, or have a lead to example >code? Thanks. Well, here are a couple of Pascal utilities that use PBGetCatInfo correctly. Hope they help. Unfortunately, while the THINK Pascal formatter makes the source look wonderful in THINK Pascal, it makes it look like shit as an ordinary text file. Hope this is readable. { ------------------------ } procedure ForAllFilesDo (volume: integer; folder: longint; foldersToo: Boolean; procedure DoFile (info: CInfoPBRec)); { loop over all files in a folder } var fileRec: CInfoPBRec; pb: WDPBRec; s: Str63; err: OSErr; oldVol, i: integer; begin with fileRec do begin ioNamePtr := @s; ioVRefNum := volume; end; FailOSErr(GetVol(nil, oldVol)); pb.ioNamePtr := nil; pb.ioVRefNum := volume; pb.ioWDDirID := folder; FailOSErr(PBHSetVol(@pb, false)); i := 1; repeat begin fileRec.ioDirID := folder; fileRec.ioFDirIndex := i; err := PBGetCatInfo(@fileRec, false); if err = noErr then begin if foldersToo | (not BitTst(@fileRec.ioFlAttrib, 3)) then begin DoFile(fileRec); fileRec.ioFDirIndex := 0; fileRec.ioDirID := folder; if PBGetCatInfo(@fileRec, false) <> fnfErr then { DoFile routine may have deleted it } i := i + 1; end else i := i + 1; end; end until err <> noErr; FailOSErr(SetVol(nil, oldVol)); end; { ------------------------ } procedure FullFileName (var outname: Str255; tail: Str255; volume: integer; dirID: longint); var name: StringHandle; text, volname: Str255; di: CInfoPBRec; hvp: HParamBlockRec; size: longint; err: integer; begin { extract the volume name } hvp.ioNamePtr := @volname; hvp.ioVRefNum := volume; hvp.ioVolIndex := 0; FailOSErr(PBHGetVInfo(@hvp, false)); if hvp.ioVSigWord = $d2d7 then FailOSErr(wrgVolTypErr); { create and initialize the name handle } size := length(tail) + 1; name := StringHandle(NewHandle(size)); FailNil(name); BlockMove(@tail, Handle(name)^, size); { now start extracting the dirs and prepending them to the handle } while dirID <> 2 do begin text := ''; di.ioNamePtr := @text; di.ioVRefNum := volume; di.ioFDirIndex := -1; di.ioDrDirID := dirID; FailOSErr(PBGetCatInfo(@di, false)); text := concat(text, ':'); size := size + length(text); SetHandleSize(Handle(name), size); name^^ := concat(text, name^^); dirID := di.ioDrParID; end; { prepend the volume name onto the handle } volname := concat(volname, ':'); size := size + length(volname); SetHandleSize(Handle(name), size); name^^ := concat(volname, name^^); { copy and delete the handle } if size > 255 then Failure(minErr, 0); outname := name^^; DisposHandle(Handle(name)); end; -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com "When errors are found in old research, the relevant theories are re-examined. When facts contradict theory, theory gets dumped. Is that why the NLP people are unwilling to research their facts?" -- Jerry Hollombe on sci.psychology