nath
nath

Reputation: 2848

Copy file to App Document folder automatically

I want to copy set of files from project resource folder to the app document folder automatically at the time of app first launch. Can I do this. Do I need to do it through the code.

Upvotes: 1

Views: 2206

Answers (1)

Retterdesdialogs
Retterdesdialogs

Reputation: 3210

BOOL success;
NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];

NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Data.txt"];

success = [fileManager fileExistsAtPath:filePath];
if (!success) {     
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"txt"];
    success = [fileManager copyItemAtPath:path toPath:filePath error:&error];

}

In application did finish launching with options

Upvotes: 6

Related Questions