问题描述
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:
,
并创建副本失败的目录。
and creating the directory the copy to fail.
这篇关于将文件夹从iPhone Resources目录复制到文档目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!