views:

40

answers:

2

I dont know the exact code i need to retrieve all of the filenames of the resources in my iphone apps mainBundle. if i could have some kind of code like:

  NSArray *array = [[NSBundle mainBundle] getAllResourceFilenames];

it would be helpful. thanks inadvanced for any help!

+2  A: 

You can get the resources path of the main bundle

[[NSBundle mainBundle] resourcePath];

and then simply use the regular NSFileManager methods to get its contents.

xtina
does this return to me a list of filenames?
Dick Savagewood
Nope, that will just give you the correct path, you will then need to use NSFileManager to get the list of files and/or subdirectories (see Seamus' answer below).
xtina
okay thanks! i got it to work :D
Dick Savagewood
+1  A: 

You should look at the SDK documentation for NSFileManager, but this will get you started:

NSString *path = [[NSBundle mainBundle] resourcePath];
NSFileManager *fm = [NSFileManager defaultManager];

NSError *error = [[NSError alloc] init];

NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];
Seamus Campbell