在iphone sdk中将文件夹从资源复制到文档

时间:2012-03-02 05:09:12

标签: iphone objective-c ios ios4

我在资源中有一个子文件夹,名称为SketchImages,其中包含300个PNG图像,我需要做的是在我的应用程序启动时将此文件夹复制到iphone sdk的文件夹中,我正在尝试以下代码,没有运气< / p>

BOOL success;
NSFileManager *fileManager = [[NSFileManager defaultManager] init];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentDBFolderPath = [documentsDirectory     
stringByAppendingPathComponent:@"SketchImages"];
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];
}

任何帮助都会受到高度关注

1 个答案:

答案 0 :(得分:1)

您使用了错误的子文件夹名称:

NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath]
    stringByAppendingPathComponent:@"SketchImages"];