iphone - NSFileManager - Copying Files at Startup -


I need to copy some sample files from the resource folder of my app and place them in the document folder of my app. I came with the attached code, it compiles fine but it does not work All the directories I mention are present I'm not sure what I am doing, can someone tell me in the right direction?

  NSFileManager * manager = [NSFileManager defaultManager]; NSString * dirToCopyTo = [NSHome directory (stringByAppendingPathComponent: @ "document"]; NSString * path = [[NSBundle main bundle] resource path]; NSString * dirToCopyFrom = [Path Stringbacking Padding Contract: @ "Samples"]; NSError * error; NSArray * Files = [Directory Content on DirectoryAct Path: DIRECTOQAFRUM: Zero]; (NSString * file in file) {[Manager copyItemAtPath: [dirToCopyFrom stringbappingpace: Company: toPath: dirToCopyTo error: & amp; Error]; If (error) {nslog (@ "% @", [error localization]]; }}  

Edit: I've just edited the code as it should be. Now there is another problem:

2010-05-15 13: 31: 31.787 mobile [4587: 207] DAMutableDictionary.h 2010-05-15 13: 31: 31.795 wrapped mobile [4587]: 207] Filemanager error: Operation could not be completed. File exists

EDIT: I have fixed this issue by telling the names of destinations copied to the NSFIF Manager. ] ToPath: [dirToCopyTo StringBeeAppendingPathComponent: file] Error: & amp; Error];

I think the problem is in this line:

  NSArray * files = [manager contentoff directoryAct Path: DRTOcopyto error: zero];  

You are listing files in the destination directory instead of the source. Change it like this:

  NSArray * files = [Manager ContentoffEdit Path: dirToCopyFrom Error: Zero];  

And you should be okay.


Comments