Search code examples
iosnsfilemanager

Cocoa Error 256 when getting file list in application resources folder


The following code is outputting The operation couldn’t be completed. (Cocoa error 256.) and the filenames NSArray is null/empty. There should be files in this folder, any ideas whats broken?

NSError *error;
NSFileManager *fm = [NSFileManager defaultManager]; 
filenames = [fm contentsOfDirectoryAtPath:[[NSBundle mainBundle] pathForResource:@"files" ofType:nil] error:&error];

NSLog(@"%@", [error localizedDescription]);

EDIT

[[NSBundle mainBundle] pathForResource:@"files" ofType:nil] is returning null for some reason


Solution

  • Nil extensions aren't folders, iOS treats them like files. You have to use -resourcePath then append the name of your folder instead.