Cocoa Filename Question

Posts: 2
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
Posts: 133
Joined: 2008.05
Post: #2
Just replace the JString with a char* I believe.
CFStringRef str;
JString returnval;
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef bundleLocation = CFBundleCopyBundleURL(mainBundle);
str = CFURLCopyPath(bundleLocation);
returnval = CFStringGetCStringPtr(str,kCFStringEncodingMacRoman);
Quote this message in a reply
Posts: 469
Joined: 2002.10
Post: #3
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?

15.4" MacBook Pro revA
Quote this message in a reply
Posts: 2
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 4,383 Jul 27, 2006 10:07 PM
Last Post: OneSadCookie
  Cocoa/Objective-C Question infernooo 2 3,881 Oct 18, 2005 11:26 PM
Last Post: infernooo
  Quick threaded OpenGL drawing question in Cocoa TomorrowPlusX 2 4,634 Nov 11, 2004 05:23 AM
Last Post: TomorrowPlusX
  Cocoa: Tile Question Criollo 15 8,084 Oct 3, 2003 02:02 AM
Last Post: Criollo
  Cocoa Question Jake 7 5,299 Jun 2, 2003 07:03 PM
Last Post: Feanor