[futurebasic] Re: [FB] FSSpecs vs FSRefs

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Sat, 26 Jan 2008 22:56:21 -0500
Just a note from Apple concerning the recommended method for  
accessing files inside the bundle of a Mach-O application:

"For Core Foundation programs, the most commonly used functions for  
finding resources are CFBundleCopyResourceURL and  
CFBundleCopyResourceURLsOfType."

Source:
http://developer.apple.com/documentation/CoreFoundation/Conceptual/ 
CFBundles/Tasks/locatingresources.html

These functions rely on CFURLRefs to do the lifting and, at least in  
my estimation, are the epitome of simplicity. Almost all the Apple  
source code examples I see accessing bundle files and resources rely  
on CFURLRefs.

For instance, using FSRefs to locate all the files in a given  
directory, you would have to write code to iterate through the  
directory contents a file at a time, check teach file to see if it is  
a file you wish to use, and store its FSRef in an array for future  
retrieval. As can be seen from recent posts here, that can be a chore.

Assuming you have a folder in your application bundle named  
"BirdImages," and you want to store all the JPEG files in the  
BirdImages directory in an array for future use, here is the complete  
code to do the job:


dim as CFArrayRef  birdURLs

birdURLs = fn CFBundleCopyResourceURLsOfType( mainBundle,¬
                                          fn CFSTR("jpg"),¬
                                   fn CFSTR("BirdImages") )


Anyone want to submit a demo doing the same with FSRefs?


Ken