Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!rutgers!cbmvax!vu-vlsi!swatsun!jackiw From: jackiw@cs.swarthmore.edu (Nick Jackiw) Newsgroups: comp.sys.mac.programmer Subject: Re: opendir() and readdir() Message-ID: <0FYB6RB@cs.swarthmore.edu> Date: 28 Dec 89 19:40:11 GMT References: <2618@draken.nada.kth.se> Reply-To: jackiw@cs.swarthmore.edu (Nick Jackiw) Organization: Visual Geometry Project, Swarthmore College, PA Lines: 84 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