2011-08-11 8 views
2

私は、アプリケーションバンドルから特定のファイルをユーザーのApplication Supportフォルダにコピーする必要があるアプリケーションを作成しています。これは私が実際に使っているコードです:アプリケーションバンドルからユーザーのApplication Supportフォルダにファイルをコピーします。

これは何もコピーしません、これはMacアプリです。あなたのファイルパスを二重にチェックすることをお勧めします

答えて

5

が最後にそれが

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]; 
0

NSLog(@"src: %@", [thisBundle pathForResource:@"db" ofType:@"sqlite"]); 
NSLog(@"dst: %@", saveFilePath); 
+0

さてさて、それを得ました次のものを扱います:if([fileManager fileExistsAtPath:userpath] == NO) [fileManager createDirectoryAtPat h:userpath withIntermediateDirectories:YES属性:nilエラー:nil]; – pmerino

+0

私はコードが動作している..しかし、問題があります。ファイルサイズが3.6メガバイトだとすると、ドキュメントディレクトリにコピーされたファイルのみが200kbのみです。これは部分的にコピーされています。それにはどんな制限がありますか? –

関連する問題