Help: List contents of iPhone application bundle subpath??
Posted
by bluepill
on Stack Overflow
See other posts from Stack Overflow
or by bluepill
Published on 2010-05-20T13:37:25Z
Indexed on
2010/05/20
13:40 UTC
Read the original article
Hit count: 201
iphone
Hi, I am trying to get a listing of the directories contained within a subpath of my application bundle. I've done some searching and this is what I have come up with
- (void) contents {
NSArray *contents = [[NSBundle mainBundle] pathsForResourcesOfType:nil
inDirectory:@"DataDir"];
if (contents = nil) {
NSLog(@"Failed: path doesn't exist or error!");
} else {
NSString *bundlePathName = [[NSBundle mainBundle] bundlePath];
NSString *dataPathName = [bundlePathName stringByAppendingPathComponent:
@"DataDir"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableArray *directories = [[NSMutableArray alloc] init];
for (NSString *entityName in contents) {
NSString *fullEntityName = [dataPathName
stringByAppendingPathComponent:entityName];
NSLog(@"entity = %@", fullEntityName);
BOOL isDir = NO;
[fileManager fileExistsAtPath:fullEntityName isDirectory:(&isDir)];
if (isDir) {
[directories addObject:fullEntityName];
NSLog(@" is a directory");
} else {
NSLog(@" is not a directory");
}
}
NSLog(@"Directories = %@", directories);
[directories release];
}
}
As you can see I am trying to get a listing of directories in the app bundle's DataDir subpath. The problem is that I get no strings in my contents NSArray.
note:
- I am using the simulator
- When I manually look in the .app file I can see DataDir and the contents therein
- The contents of DataDir are png files and directories that contain png files
- The application logic needs to discover the contents of DataDir at runtime
- I have also tried using
NSArray *contents = [fileManager contentsOfDirectoryAtPath:DataDirPathName error:nil];
and I still get no entries in my contents array
Any suggestions/alternative approaches?
Thanks.
© Stack Overflow or respective owner