views:

628

answers:

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

Like this.

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

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.

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

+3  A: 

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

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

The file specified in srcPath must exist, while dstPath must not exist prior to the operation

and creating the directory the copy to fail.

KennyTM
OH!! really really really thanks!! thanks!!
Beomseok