我想将文件从应用程序资源复制到文档目录。我正在使用此代码,但这会将文件复制到我自己的应用程序文档目录中。
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");
}
我曾尝试将此代码更改为,但它不起作用也许是这样的
NSString *storePath = [documentsDirectory stringByAppendingPathComponent: @"Applications/AppFolder/Documents/TestFile.txt"];
那么有没有办法将文件复制到不同的目录?