iPhone OS Directory Structure
- Application Home
+--- appName.app : your app is stored here. includes resources, plists and etc.
+--- Documents
+--- Library
+--- Preferences
+--- Caches
+---- Tmp
example1) getting Documents Directory
- (NSString *) applicationDocumentDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
}
NSLog(@"DocumentDirectory %@", [self applicationDocumentDirectory]);
output1)
/Users/alice/Library/Application Support/iPhone Simulator/4.2/Applications/BC8D9596-402B-4B74-9F75-DE8EBD497F38/Documents
example2) getting current application directory
NSLog(@"Application Directory:%@", [[NSBundle mainBundle] bundlePath]);
output2)
simple[5920:207] Application Directory:/Users/alice/Library/Application Support/iPhone Simulator/4.2/Applications/BC8D9596-402B-4B74-9F75-DE8EBD497F38/simple.app
example3) getting a file list of a directory
NSString *filePath = [[NSBundle mainBundle] bundlePath];
NSArray *fileList = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:filePath error:nil];
NSLog(@"fileList: %@", fileList);
output3)
simple[5970:207] fileList: (
"blog_flower.jpg",
"flower.png",
"Info.plist",
"MainWindow.nib",
PkgInfo,
simple,
"simpleViewController.nib"
)
example4) filtering a file list
NSString *filePath = [[NSBundle mainBundle] bundlePath];
NSArray *fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
NSArray *filtered = [fileList pathsMatchingExtensions:[NSArrayarrayWithObjects:@"png", @"jpg", @"tiff", @"pdf", nil]];
output4)
simple[5970:207] filtered: (
"blog_flower.jpg",
"flower.png"
)