沙盒中创建文件夹
NSFileManager*fileManager = [[NSFileManageralloc]init];NSString*pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES)objectAtIndex:0];NSString*createPath = [NSStringstringWithFormat:@"%@/collect_deals.data",pathDocuments];if(![[NSFileManagerdefaultManager]fileExistsAtPath:createPath]) {
[fileManager createDirectoryAtPath:createPath withIntermediateDirectories:YESattributes:nilerror:nil];
}else{NSLog(@"有这个文件了");
}
这样我们就在沙盒Documents中创建好了名为collect_deals.data的文件夹。那我们现在来获取沙盒路径
NSLog(@"%@",[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) lastObject] stringByAppendingPathComponent:@"collect_deals.data"]);
我们获得到类似如下路径
/User/SYH/Library/Developer/CoreSimulator/Devices/5B8713E8-CD24-4E78-90F3-8F8DA0D2B035/data/Containers/Data/Application/863172CE-8ACC-460B-B8F7-E897BF059DDE/Documents/collect_deals.data
我们打开Finder前往文件夹 ,现在是否在沙盒中就有了这个文件夹呢?是不是很简单!