文件-沙盒目录代码段;

来源:互联网 发布:猜幻数游戏编程c语言 编辑:程序博客网 时间:2024/06/03 20:21
#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];  //这个函数里面已经有文件存在与否的判断;    }

0 0
原创粉丝点击