Search code examples
iosnsmutablearraynsarraynsdocumentdirectory

iPhone SDK Xcode - How to get all the filenames in the documents dir


I want to get all the filenames in my application's documents folder, and place them in an NSMutableArray. Nothing more, nothing less.


Solution

  • There is a convenient method in NSFileManager:

    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory 
                                                      error:nil];
    ...
    [fileManager release];
    

    As of ARC you can of course drop the release statement.