Language/Objective-C

[Iphone] Iphone OS Directory Structure

아르비스 2011. 5. 24. 16:06

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,NSUserDomainMaskYESobjectAtIndex: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 mainBundlebundlePath]);

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 mainBundlebundlePath]; 

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 mainBundlebundlePath]; 

NSArray *fileList = [[NSFileManager defaultManagercontentsOfDirectoryAtPath:filePath error:nil]; 

NSArray *filtered = [fileList pathsMatchingExtensions:[NSArrayarrayWithObjects:@"png"@"jpg"@"tiff"@"pdf"nil]];

output4)

simple[5970:207] filtered: (

    "blog_flower.jpg",

    "flower.png"

)