iOS应用目录

iOS程序都是在沙盒里面运行的,但是具体目录是咋样的呢?我写了个函数,list了所有的目录(包括文件)。咱们先来看一下:

- (void)fileList:(NSString*)directory{
    printf(">>>:%s\n",[directory UTF8String]);
    NSError *error = nil;
    NSFileManager * fileManager = [NSFileManager defaultManager];
    NSArray *fileList = [fileManager contentsOfDirectoryAtPath:directory error:&error]; 
    for (NSString* each in fileList) {
        NSMutableString* path = [[NSMutableString alloc]initWithString:directory];
        [path appendFormat:@"/%@",each];
        [self fileList:path];
        [path release];
    }
}


调用:
 
[self filelist:NSHomeDirectory()];


来看一下打印结果:

真机:

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/Directory

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/Info.plist

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/PkgInfo

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/ResourceRules.plist

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/_CodeSignature

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/_CodeSignature/CodeResources

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/embedded.mobileprovision

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/en.lproj

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/en.lproj/InfoPlist.strings

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/en.lproj/ViewController_iPad.nib

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Directory.app/en.lproj/ViewController_iPhone.nib

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Documents

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Library

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Library/Caches

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Library/Preferences

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Library/Preferences/.GlobalPreferences.plist

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/Library/Preferences/com.apple.PeoplePicker.plist

>>>:/var/mobile/Applications/A3209D39-4D02-40C2-99B4-4111A218CF1F/tmp


模拟器:

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/Directory

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/en.lproj

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/en.lproj/InfoPlist.strings

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/en.lproj/ViewController_iPad.nib

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/en.lproj/ViewController_iPhone.nib

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/Info.plist

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Directory.app/PkgInfo

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Documents

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Library

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Library/Caches

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Library/Preferences

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Library/Preferences/.GlobalPreferences.plist

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/Library/Preferences/com.apple.PeoplePicker.plist

>>>:/Users/liuwei/Library/Application Support/iPhone Simulator/5.1/Applications/595FAC37-23AA-434A-84BE-3274C7A8A6F1/tmp


分析:

虽然真机和模拟器有点不一样,但是其实是大同小异。NSHomeDirectory() 是获取沙盒的根目录,然后就是他下面的其他目录:Directory.app(Directory是我这个工程的名字)、Documents、Library、tmp,Library下面又有一些子目录等等。

Directory.app 是程序包目录,主要包含和程序相关的文件,Documents你可以自己放一些文件到这个目录下,Library 也是个重要的目录,比如你的NSUserDefaults的数据就是在Libarary下面的Preferences中,还有 Caches 等等,tmp看名字就知道是一个存放临时文件的。我们主要用到的还是documentd和library。


不多说了,要想明白,自己把我的代码copy过去试一下就知道了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值