您的位置:首页 > 编程语言

文件-沙盒目录代码段;

2014-09-12 10:58 148 查看
#pragma mark -把文件复制到沙盒目录;
- (BOOL)copyFilePath:(NSString *)fromPath toPath:(NSString *)toPath{

NSFileManager *fileMan = [NSFileManager defaultManager];
NSError *error = nil;
if ([fileMan fileExistsAtPath:toPath]) {
debugLog(@"MDRootVC:The file %@ is exist!", toPath);
return NO;
}
BOOL retCode = [fileMan copyItemAtPath:fromPath toPath:toPath error:&error];
return retCode;
}


categoryArray = [NSMutableArray arrayWithCapacity:1];
NSString *docPth = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *toPth = [docPth stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist", DM_CATEGORY_ARR]];
/*
NSString *path111 = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];
NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths1 objectAtIndex:0];
NSLog(@"app_home_lib: %@",libraryDirectory);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"app_home_doc: %@",documentsDirectory);
*/

NSFileManager *fileMana = [NSFileManager defaultManager];
if ([fileMana fileExistsAtPath:toPth]) {
debugLog(@"这个文件已经存在,不要再复制了,程序第一次启动时已经复制了");
categoryOriginArr = [[NSArray alloc] initWithContentsOfFile:toPth];

}else{
NSString *catPth = [[NSBundle mainBundle] pathForResource:DM_CATEGORY_ARR ofType:@"plist"];
categoryOriginArr = [NSArray arrayWithContentsOfFile:catPth];
[self copyFilePath:catPth toPath:toPth];  //这个函数里面已经有文件存在与否的判断;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: