tags:

views:

531

answers:

3

hi all, i am new to Iphone programming. I want to copy a folder(which contains subfolder hierearchy and files) from resourse folder to application folder. i have no idea about this. Please suggest how can i do this task?

Thanks

A: 

You can only copy files to your applications document or tmp folders. If you change the application bundle on runtime, it will break.

I'm not sure of what you are trying to do, but here is some pointers...

Check out the NSFileManager class. First you create a filemanager:

NSFileManager *fileManager = [NSFileManager defaultManager];

Then you can list files in directories:

NSArray *files = [fileManager contentsOfDirectoryAtPath:@"somepath" error:NULL];

Then you could just loop through the array and copy them with the copyItemAtPath:toPath:error: method

if([fileManager copyItemAtPath:@"source" toPath:@"destination" error:NULL]) {
    NSLog(@"Success!");
} else {
    NSLog(@"Fail!");
}

You can get the path to your resources folder with [[NSBundle mainBundle] resourcePath].

Hope this helps.

Nino
A: 

copyItemAtPath:toPath:error will copy an entire folder to a new location, if the atPath is a directory.

mahboudz
A: 

There is some information missing here. If you want to do this at Build time:

If you have a resource folder in Xcode, with a default build configuration, then all the items of the resource folder will all be copied into your application bundle, meaning your app, whne you Build. You don't have to do any extra work.

By selecting items from the resource folder you can do a Get Info on them and select to have each included or not included in the target.

If you want to do this at Runtime:

If you want to copy items from your folder to another folder, you can follow this. However, you can't write to the Application folder. You can write to the Documents, Preferences and tmp folder and that is about it.

mahboudz