views:

400

answers:

1

What I want to do seems simple enough: Get an array of filenames in a given "directory" on my app. But the more I play around with NSFileManager and NSBundle I find myself getting more lost...I just want to get the filenames of the files organized in a specific directory in my iPhone Xcode project...For example: The directory in question is called "Images" (created using "Add > New Group" under the project icon in Xcode) and contains 10 .png images. It seems simple but I am getting nowhere. I'd appreciate some help in finding the answer.

Q: How do I get an NSArray of filenames of all files in a given directory in my app?

+5  A: 

If you want the folder to be part of the App bundle, you need to create a folder reference inside the Resources group, instead of a group (it will show up in Xcode as a blue folder as opposed to the yellow one).

To do this, you drag the folder from Finder and select folder reference when prompted.

Once you have that, you should be able to get the contents of the folder with something like:

[[NSFileManager defaultManager]
   directoryContentsAtPath:
   [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"YourFolder"];
pgb