iphone - Array of NSStrings from filenames within a folder? -
I am trying to create NSStrings of the contents of the folder that I have dragged into my project. But when I later in the array Counting items, it always comes back with 0;
Then, my folder looks like this in my project
-Cards-Colors
and my code is that of the files Tries to get the list (color pngs)
NSError * error = zero; NSString * path string = [[NSString alloc] init]; Path string = [[NSString alloc] initWithString: @ "/ card / color /"]; NSArray * fileList = [[NSARLALO] Init]; FileList = [[NSFileManager defaultManager] Contentoff DirectoryAct Path: Pathstring Error: & amp; Error]; [Route release]; NSLog (@ "% @", error); // It is always 0 NSLog (@ "File list contains% i items", [filelist count]);
I could not complete the NSERR
error domain = NSCKEdirem code = 260 "operation. (Coco Error 260.)" User Info = 0x596db00 { NSUserStringVariant = (folder), NSFilePath = / card / color /, NSUnderlyingError = 0x5925ef0 "operation could not be completed. There is no such file or directory."}
Any Idea I Got Wrong Am going
You are starting the full path to pathString
/ Card / Color /
. This path is a system-wide path, so on the iPhone, outside your app's sandbox.
Try it instead:
NSString * pathString = [[NSBundle mainBundle] PathForResource: @ "Card / Color" type: zero]; NSArray * fileList = [[NSFileManager default manager] Contentoff DirectoryAct Path: Pathstring Error: & amp; Error];
(Note that in the way you place your code in question, alloc / init fileList
, then immediately that item to contentofdientwith: error :
. This is a bug.)
Comments
Post a Comment