将文件夹从iPhone Resources目录复制到文档目录

Beo*_*eok 7 iphone objective-c

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];
 }
}
Run Code Online (Sandbox Code Playgroud)

像这样.

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

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

我真的想复制Resources文件夹中DB文件夹中的文件.请帮我.

ken*_*ytm 8

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

2)无需打电话-createDirectoryAtPath:.从SDK doc -copyItemAtPath:toPath:error:,

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

并创建目录副本失败.