将文件夹从iPhone Resources目录复制到文档目录 [英] Copy folder from iPhone Resources directory to document directory

查看:151
本文介绍了将文件夹从iPhone Resources目录复制到文档目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BOOL success;
NSFileManager *fileManager = [[NSFileManager defaultManager]autorelease];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
                                                      NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"DB"];
success = [fileManager fileExistsAtPath:documentDBFolderPath];

if (success){
 return;
}else{
 NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath]
                                         stringByAppendingPathComponent:@"DB"];
 [fileManager createDirectoryAtPath: documentDBFolderPath attributes:nil];
    [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath           
                                                                         error:&error];
 }
}

喜欢这个。

Resources / DB / words.csv => DB folder copy => Document / DB / words.csv

Resources/DB/words.csv => DB folder copy => Document/DB/words.csv

我想复制DB子目录at资源文件夹。我认为这个来源很好。但该源创建文件夹,不会复制Resources文件夹中DB文件夹中的文件。

I want to copy DB subdirectory at Resources folder. I thought that source is good. But that source makes folder and doesn't copy files in DB folder at Resources folder.

我真的想要复制Resources文件夹中DB文件夹中的文件。请帮助我。

I really want to copy files in DB folder at Resources folder. please help me.

推荐答案

1)不要 -autorelease NSFileManager 。你是双重释放它会使你的应用程序崩溃。

1) Do not -autorelease the NSFileManager. You are double-releasing it which will crash your app.

2)无需调用 -createDirectoryAtPath:。来自 -copyItemAtPath:toPath的SDK文档:错误:

2) No need to call -createDirectoryAtPath:. From the SDK doc of -copyItemAtPath:toPath:error:,


文件在操作之前, srcPath 中指定的 dstPath 必须不存在

并创建副本失败的目录。

and creating the directory the copy to fail.

这篇关于将文件夹从iPhone Resources目录复制到文档目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆