0

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

Kurru
  • 14,180
  • 18
  • 64
  • 84
  • "error code 256 can occur when an unknown error is occurred in reading the resource or the path has some encoded characters in it." – CodaFi May 21 '12 at 03:38
  • are you trying to go for "files" folder? or is this is a filename of some type? – rishi May 21 '12 at 03:43
  • I'm getting a null pointer for the path of the files folder. (resources/files) – Kurru May 21 '12 at 03:49

1 Answers1

2

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

CodaFi
  • 43,043
  • 8
  • 107
  • 153
  • Got it working again. I had a group but changed it to a folder. I think... Its got a blue icon now anyway. No idea what that means – Kurru May 21 '12 at 04:09
  • 1
    Ah! I see. Groups in Xcode aren't folders, they are merely graphical representations of a set of files. The blue folders and finder folder, those are real. That's how you got it working. – CodaFi May 21 '12 at 04:22