ThinkC Equivalent to "dir *.PICT"

Relating to ThinkC Development

Mu0n

Active Tinkerer
Oct 29, 2021
573
532
93
Quebec
www.youtube.com
In MSDOS, it's very easy to get a list of files with a restriction in the name, for example its suffix.

INI:
dir *.txt

and you can send the result to an output stream other than the screen, for example, a file

Diff:
dir *.txt > results.txt

I already know how to use the olden Macintosh file retrieval dialog (SFGetFile) and perform a restriction by file type, but what if I just wanted a *list* of those files, outside of the context of that dialog with canned behavior?

My use case: as soon as my app launches, load a bunch of MacPaint files (or PICT files) in the same folder as the app, within reason (stop before memory runs out).
 

Crutch

Tinkerer
Jul 10, 2022
292
226
43
Chicago
Use PBGetCatInfo(). Pass in a volume reference number you get from GetVol(), this will be the working directory your application is in. Pass in ioFDirIndex = 1 and then increment from there until you get an error (if you run out of files, you will get an fnfErr back from PBGetCatInfo). Each time you will get info on a file or directory in your working directory. Check bit 4 of ioFlAttrib (take ioFlAttrib & 0x10) on the result param block, if 1 you are looking at a folder (increment ioFDirIndex and repeat); if 0, it’s a file. Check the type of the file (ioFlFndrInfo.fdType in the paramblock) to see if it’s a PNTG. If so, you have got yourself a MacPaint document!

See Inside Mac Volume IV, p. 126.
 
Last edited:
  • Like
Reactions: Patrick and Mu0n