Reputation: 21
I want to copy a file from app resources to documents directory. I'm using this code, but this will copy the file to my own application documents directory.
NSFileManager* fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *storePath = [documentsDirectory stringByAppendingPathComponent: @"TestFile.txt"];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TestFile" ofType:@"txt"];
[[NSFileManager defaultManager] copyItemAtPath:filePath toPath:storePath error:nil];
if (![fileManager fileExistsAtPath:getDatabasePath]) {
NSLog(@"file doesn't exist");
// file doesn't exist
} else {
NSLog(@"file exist");
}
Which I have try to change this code as, but it doesn't work maybe it's something like this
NSString *storePath = [documentsDirectory stringByAppendingPathComponent: @"Applications/AppFolder/Documents/TestFile.txt"];
So is there any possible way to copy file to different directory?
Upvotes: 2
Views: 2678
Reputation: 12719
You cannot copy resources of one application to other application from inside any application, because you will not get any reference of the other application. Each application has its auto generated application id and you cannot access that from other application.
If you are trying to achieve in the device, its impossible, but if you're trying something in simulator, just manually copy paste the resources..
Upvotes: 2