d88-jwa@nada.kth.se (Jon Watte) (12/26/89)
It's that time of the year again. I simply want to get the names of the files in adirectory. No, I am no novice to mac programming, but I've let libraries handle file I/O for me until now. I looked through IM IV, but the HFS chapter is less than crystal clear on this point... Now, how do I search {a | the current} directory for file names (and maybe types...) ? Any code pieces or hints are welcome ! h+@nada.kth.se -- -- Stay alert ! - Trust noone ! - Keep your laser handy ! --- h+@nada.kth.se == h+@proxxi.se == Jon Watte longer .sig available on request
keith@Apple.COM (Keith Rollin) (12/26/89)
In article <2618@draken.nada.kth.se> h+@nada.kth.se (Jon W{tte) writes: > >It's that time of the year again. > >I simply want to get the names of the files in adirectory. >No, I am no novice to mac programming, but I've let libraries >handle file I/O for me until now. I looked through IM IV, but >the HFS chapter is less than crystal clear on this point... > >Now, how do I search {a | the current} directory for file >names (and maybe types...) ? Any code pieces or hints are >welcome ! Jon, Macintosh Technical Note #68 discusses the algorithm for looking at all entries in a directory, including sub-directories if you wish. It is slightly deficient in that it does not handle well situations where your directory may change out from under you. This could happen, say, on an AppleShare volume. John Norstad looked into this situation deeply, and came up with a modified algorithm that re-syncs if it finds that things have changed. If he is reading this, perhaps he could re-post his article. By the way, Inside Mac IV should be pretty clear on this. Most of page IV-101 talks about indexed calls. These include calls like PBGetVolInfo, PBGetFInfo, and PBGetCatInfo. PBGetCatInfo is the routine used in the Technote. -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions
alen@crash.cts.com (Alen Shapiro) (12/27/89)
In article <2618@draken.nada.kth.se> h+@nada.kth.se (Jon W{tte) writes: > >It's that time of the year again. > >I simply want to get the names of the files in adirectory. >No, I am no novice to mac programming, but I've let libraries >handle file I/O for me until now. I looked through IM IV, but >the HFS chapter is less than crystal clear on this point... > >Now, how do I search {a | the current} directory for file >names (and maybe types...) ? Any code pieces or hints are >welcome ! > The uupc sources implement the UNIX independent directory manipulation functions (opendir, readdir, closedir, etc.) I'm not sure as to their status for inclusion in other works but they WERE published on the net. If I don't get any mail telling me not to, I'll email the relevant bits to the requestor - this is posted to the net in case the request is of general interest. --alen the Lisa slayer (it's a long story) ...alen%shappy@crash.cts.com (a mac+ uucp host - what a concept) ps uupc v2.0 unofficial upgrade for THINK LSC4.0 has been posted to comp.binaries.mac - it may appear soon.
jackiw@cs.swarthmore.edu (Nick Jackiw) (12/29/89)
h+@nada.kth.se (Jon W{tte) writes: > I simply want to get the names of the files in adirectory. > No, I am no novice to mac programming, but I've let libraries > handle file I/O for me until now. I looked through IM IV, but > the HFS chapter is less than crystal clear on this point... > > Now, how do I search {a | the current} directory for file > names (and maybe types...) ? Any code pieces or hints are > welcome ! > > h+@nada.kth.se > -- Try this. program enumerateDir; var ourParam: ParmBlkPtr; {For finding ChainMail file in System Folder} ourWDParam: WDPBPtr; {For opening a working directory} mailBoxAddr, mailFileName: str255; fileNum: integer; {For indexing all SysFolder files} theErr: OSErr; {Misc. OS Call error code} begin MailBoxAddr:='Saturn:System Folder:'; {**whatever**} with ourWDParam^ do begin ioCompletion := nil; ioNamePtr := @MailBoxAddr; ioVRefNum := 0; ioWDProcID := 0; ioWDDirId := 0; end; if PBOpenWD(ourWDParam, false) <> noErr then begin writeln('Too many working directories open!'); readln end; writeln('Here goes!'); fileNum := 1; {Begin examining all files} with ourParam^ do begin ioCompletion := nil; ioNamePtr := @mailFileName; ioVRefNum := ourWDParam^.ioVRefnum; mailFileName := ''; end; repeat ourParam^.ioFDirIndex := fileNum; theErr := PBGetFInfo(ourParam, false); if theErr = noErr then begin writeln(mailFileName, ' ', ourParam^.ioFlFndrInfo.fdType, ' ', ourParam^.ioFlFndrInfo.fdCreator); end; fileNum := succ(fileNum); until theErr <> noErr; end. Sorry about all the tabs...vi seems to have a wider setting than LSP. This is a fragment cut from working code. Reading it once, nothing looks spurious, but there may be references to the particular system in which it was formerly embedded. The last writln in the program should list the filename, file type, and creator field, as per your request. -Nick -- -----Nicholas Jackiw [jackiw@cs.swarthmore.edu|jackiw@swarthmr.bitnet]----- "Here is how I built this artificial mine. I snatched a female louse from the hair of humanity. I was seen to lie with her on three successive nights, and then I flung her into the pit." _Maldoror_, Canto II