Cocoa Filename Question

Nibbie
Posts: 1
Joined: 2010.11
Post: #1
Is is possable to find out where the app bundle is located? If so there how would you get the file refrence to the folder that the app is in?


if not... cocoa sucks :ouch:

[edit] also how do you load the file names from a folder into adn array and get the # of files in the folder?
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #2
Just replace the JString with a char* I believe.
Code:
CFStringRef str;
JString returnval;
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef bundleLocation = CFBundleCopyBundleURL(mainBundle);
str = CFURLCopyPath(bundleLocation);
returnval = CFStringGetCStringPtr(str,kCFStringEncodingMacRoman);
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #3
Code:
NSBundle *bundle = [NSBundle mainBundle];
//to get a particular file in the bundle's resources:
NSString *path1 = [bundle pathForResource:@"readme" ofType:@"txt"];

//to get a file in a subdir:
NSString *path2 = [bundle pathForResource:@"level2" ofType:@"txt" inDirectory:@"levels"];

//to get just the path to the resources:
NSString *toppath = [bundle resourcePath];

//to get that array of files in your resource directory:
NSArray *files = [[NSFileManager defaultManager] directoryContentsAtPath:toppath];

make sense?

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #4
Um.. Actually I'm wonderhing how to get... Oh never mind Smile . That'll do. Thanks!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Newbie question: Cocoa and Carbon - which for what and how to get started? BliTz 3 3,113 Jul 27, 2006 10:07 PM
Last Post: OneSadCookie
  Cocoa/Objective-C Question infernooo 2 3,090 Oct 18, 2005 11:26 PM
Last Post: infernooo
  Quick threaded OpenGL drawing question in Cocoa TomorrowPlusX 2 3,793 Nov 11, 2004 05:23 AM
Last Post: TomorrowPlusX
  Cocoa: Tile Question Criollo 15 5,835 Oct 3, 2003 02:02 AM
Last Post: Criollo
  Cocoa Question Jake 7 4,106 Jun 2, 2003 07:03 PM
Last Post: Feanor