IPhone (iOS): copying files from main bundle to documents folder error?

Your destination path must contain the name of item being copied, not just the documents folder. Try: if(NSFileManager defaultManager copyItemAtPath:sourcePath toPath:documentsDirectory stringByAppendingPathComponent:@"Populator" error:&error){ Edit: Sorry misunderstood your question. Don't know if there's a better option then iterating through folder contents and copy each item separately.

If you're targeting iOS4 you can use NSArray's enumerateObjectsUsingBlock: function for that: NSArray* resContents = NSFileManager defaultManager contentsOfDirectoryAtPath:copyItemAtPath:sourcePath error:NULL; resContents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSError* error; if (!NSFileManager defaultManager copyItemAtPath:sourcePath stringByAppendingPathComponent:obj toPath:documentsDirectory stringByAppendingPathComponent:obj error:&error) DLogFunction(@"%@", error localizedDescription); } P.S. If you can't use blocks you can use fast enumeration: NSArray* resContents = NSFileManager defaultManager contentsOfDirectoryAtPath:copyItemAtPath:sourcePath error:NULL; for (NSString* obj in resContents){ NSError* error; if (!NSFileManager defaultManager copyItemAtPath:sourcePath stringByAppendingPathComponent:obj toPath:documentsDirectory stringByAppendingPathComponent:obj error:&error) DLogFunction(@"%@", error localizedDescription); }.

Your destination path must contain the name of item being copied, not just the documents folder. Try: if(NSFileManager defaultManager copyItemAtPath:sourcePath toPath:documentsDirectory stringByAppendingPathComponent:@"Populator" error:&error){ ... Edit: Sorry misunderstood your question. Don't know if there's a better option then iterating through folder contents and copy each item separately.

If you're targeting iOS4 you can use NSArray's -enumerateObjectsUsingBlock: function for that: NSArray* resContents = NSFileManager defaultManager contentsOfDirectoryAtPath:copyItemAtPath:sourcePath error:NULL; resContents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSError* error; if (!NSFileManager defaultManager copyItemAtPath:sourcePath stringByAppendingPathComponent:obj toPath:documentsDirectory stringByAppendingPathComponent:obj error:&error) DLogFunction(@"%@", error localizedDescription); }; P.S. If you can't use blocks you can use fast enumeration: NSArray* resContents = NSFileManager defaultManager contentsOfDirectoryAtPath:copyItemAtPath:sourcePath error:NULL; for (NSString* obj in resContents){ NSError* error; if (!NSFileManager defaultManager copyItemAtPath:sourcePath stringByAppendingPathComponent:obj toPath:documentsDirectory stringByAppendingPathComponent:obj error:&error) DLogFunction(@"%@", error localizedDescription); }.

Thanks for the response, but this is not what I want to do. What I want to do is copy the contents of the Populator folder to the directories root (not a folder called Populator in the documents root). What you are saying to do does work, but is not what I want to achieve.

– Jack Jul 14 '10 at 12:53 Thanks a lot, the misunderstanding was almost certainly my fault. I am using this code for an iPad application, so will be targeting iOS 3.2, although eventually this will support iOS4. Thanks for your code, any idea how to get it working for 3.2 (without blocks)?

– Jack Jul 14 '10 at 13:25 1 I've added code using fast enumeration. Blocks solution was more to exercise myself - blocks are a new concept for me. – Vladimir Jul 14 '10 at 13:34 Thank you so much, really appreciate the effort.

– Jack Jul 14 '10 at 13:46.

A note: don't issue lengthy operation in didFinishLaunchingWithOptions: is a conceptual mistake. If this copy takes too much time, watchdog will kill you. Launch it in a secondary thread or NSOperation... I personally use a timer proc.

I am trying to copy some files across from my app bundle to the documents directory on first launch. I have the checks in place for first launch, but they're not included in code snippet for clarity. DstPath must not exist prior to the operation.

What is the best way for me to achieve the copying straight to the documents root? The reason I want to do this is to allow iTunes file sharing support.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions