0

I want to list the files from a group (a subdirectory) that is in resources. In my application I have a directory named "4x4"; in Xcode I created a group "4x4" into resources and I added all the files of the directory "4x4" to that group. Now, I'm making this:


NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"4x4"];
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = [[NSError alloc] init];
NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];

It gaves me a null array, and if I check if the directory existes it tells me that it doesn't exist. If I try to list the files of the mainBundle (without the "4x4" group) it gaves me all the files, but I don't want them.

What should I do? Do you have any idea or do you know the right way?

Thanks in advance!

pablomarti
  • 2,087
  • 2
  • 22
  • 35

1 Answers1

4

The fact that you created a folder on disk or a group in your Xcode project doesn't mean that those files end up in a subdirectory in your app's bundle. By default, Xcode will copy all resources into the bundle's root directory.

To create a subdirectory in your bundle and add those files to it, you have to create a custom "Copy Files" build phase to your target in Xcode. In the properties of the build phase, you can specify the directory.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256