UI-senior(数据本地化-获取文件夹路径)


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

#pragma mark ----第一种获取文件夹地址的方式----

       //NSDocumentDirectory:表示获取Document文件夹的地址

      //NSUserDomainMask:表示用户的主目录

      //参数三:表示展开....的地址,设置为Yes表示为完整的路径

      //NSSearchPathForDirectoriesInDomains获取的是一个数组,数组只有一个元素,所以直接赋下标为0;   

NSString *documentPathStr =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSLog(@"%@",documentPathStr);

//获取Library文件的路径
NSString *libraryPathStr = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSLog(@"%@",libraryPathStr);

#pragma mark ----第二种获取沙盒主路经的地址------

//step1:获取沙盒主路经地址

NSString *homePathStr = NSHomeDirectory();

NSLog(@"homePathStr =====%@",homePathStr);

//step2:在沙盒主路经后面拼接Documents ,拼接出来documents文件夹的路径

NSString *document1PathStr = [homePathStr stringByAppendingPathComponent:@"Documents"];

NSLog(@"homePathStr =====%@",document1PathStr);

//step2:在沙盒主路经后面拼接想要获取的全路径

NSString *cachePathStr = [homePathStr stringByAppendingPathComponent:@"Library/Caches"];

NSLog(@"cachePathStr =====%@",cachePathStr);

#pragma mark ----特例:获取tmp路径------

NSString *tmpPathStr = NSTemporaryDirectory();

NSLog(@"tmpPathStr === %@",tmpPathStr);

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

你可能感兴趣的:(UI-senior(数据本地化-获取文件夹路径))