Alex Rivera | Logout

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

Asked 2009-08-13T13:43:03.307
10

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?

Edit
Report

1 Answer

9

The accepted answer's been deprecated for years now. The following should be used instead.

- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error

Update: @macserv updated the accepted answer after I posted this.

answered 2012-03-29T21:51:24.787

Your Answer