2012-03-02 111 views
1

我有一个名为SketchImages的子文件夹,其中包含300个PNG图像,我需要做的是在我的应用程序启动时将此文件夹复制到iphone sdk文档文件夹中,我我想,没有运气复制文件夹从资源到文档在iphone中sdk

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]; 
} 

任何帮助将高度appriciated

+0

目录目录? 它会增加你的iPhone的应用程序大小... – 2012-03-02 05:21:17

+0

我正在绘制一本书,我需要这样做 – 2012-03-02 05:35:33

+0

当你调用copyItemAtPath时会返回什么错误? – Nevin 2012-03-02 05:55:48

回答

1

您使用了错误的子文件夹名称下面的代码:你为什么要复制所有图像做

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

它不是关于文件夹名称此代码不起作用 – 2012-03-02 05:33:45

+0

@AbdulKarimKhan您“资源中有一个名称为SketchImages的子文件夹”,并且您试图复制名为“DB”的子文件夹。由于您没有名为“DB”的资源子文件夹,因此您的代码不起作用。 – Costique 2012-03-02 07:08:55

相关问题