私は、アプリケーションバンドルから特定のファイルをユーザーのApplication Supportフォルダにコピーする必要があるアプリケーションを作成しています。これは私が実際に使っているコードです:アプリケーションバンドルからユーザーのApplication Supportフォルダにファイルをコピーします。
これは何もコピーしません、これはMacアプリです。あなたのファイルパスを二重にチェックすることをお勧めします
私は、アプリケーションバンドルから特定のファイルをユーザーのApplication Supportフォルダにコピーする必要があるアプリケーションを作成しています。これは私が実際に使っているコードです:アプリケーションバンドルからユーザーのApplication Supportフォルダにファイルをコピーします。
これは何もコピーしません、これはMacアプリです。あなたのファイルパスを二重にチェックすることをお勧めします
が最後にそれが
if ([fileManager fileExistsAtPath:userpath] == NO)
[fileManager createDirectoryAtPath:userpath withIntermediateDirectories:YES attributes:nil error:nil];
し、得られたコードを追加することで作業しまったのです。
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *userpath = [paths objectAtIndex:0];
userpath = [userpath stringByAppendingPathComponent:executableName]; // The file will go in this directory
NSString *saveFilePath = [userpath stringByAppendingPathComponent:@"db.sqlite"];
NSFileManager *fileManager = [[NSFileManager alloc] init];
if ([fileManager fileExistsAtPath:userpath] == NO)
[fileManager createDirectoryAtPath:userpath withIntermediateDirectories:YES attributes:nil error:nil];
[fileManager copyItemAtPath:[thisBundle pathForResource:@"db" ofType:@"sqlite"] toPath:saveFilePath error:NULL];
:
NSLog(@"src: %@", [thisBundle pathForResource:@"db" ofType:@"sqlite"]);
NSLog(@"dst: %@", saveFilePath);
さてさて、それを得ました次のものを扱います:if([fileManager fileExistsAtPath:userpath] == NO) [fileManager createDirectoryAtPat h:userpath withIntermediateDirectories:YES属性:nilエラー:nil]; – pmerino
私はコードが動作している..しかし、問題があります。ファイルサイズが3.6メガバイトだとすると、ドキュメントディレクトリにコピーされたファイルのみが200kbのみです。これは部分的にコピーされています。それにはどんな制限がありますか? –