繁体   English   中英

将sqlite DB从收件箱复制到文档目录

[英]copy sqlite DB From Inbox to documents directory

从邮件打开sqlite文件时,它进入我的文档目录中名为inbox的文件夹,我使用此代码将此文件复制到文档目录

- (void) copyAdd
{
NSString *docsDir;
NSArray *dirPaths;
NSString *databasePath;

NSFileManager *filemgr = [NSFileManager defaultManager];

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,        YES);
docsDir = [dirPaths objectAtIndex:0];
NSString* inboxPath = [docsDir stringByAppendingPathComponent:@"Inbox"];

// Build the path to the database file
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"CAT.sqlite"]];

if(![filemgr fileExistsAtPath:databasePath]){

    [filemgr copyItemAtPath:inboxPath toPath:databasePath error:nil];





    NSLog( @"copy create database");
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"sucess" message:@"COPY CAT DB"         delegate:self cancelButtonTitle:@"dismis" otherButtonTitles:nil, nil];
    [alert show];
}else{
    NSLog( @"Failed to open/create database");

}

它创建了名称为CAT.sqlite的文件夹,并且在此文件夹中,我找到了数据库CAT.sqlite

我如何将名为CAT.sqlite的文件从收件箱文件夹复制到文档目录,而无需创建具有相同名称的文件夹。

这是我的代码,可以解决问题,唯一缺少的是指定我需要从收件箱文件夹而非所有文件夹而是CAT.sqlite文件夹复制的文件名

 - (void) copyAdd
{
NSString *docsDir;
NSArray *dirPaths;
NSString *databasePath;

NSFileManager *filemgr = [NSFileManager defaultManager];

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString* inboxPath = [docsDir stringByAppendingPathComponent:@"Inbox"];
NSString *filePath = [inboxPath stringByAppendingPathComponent:@"CAT.sqlite"];

// Build the path to the database file
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"CAT.sqlite"]];

if(![filemgr fileExistsAtPath:databasePath]){

    //        NSLog(@"dbPAth : %@",dbPAth);
    [filemgr copyItemAtPath:filePath toPath:databasePath error:nil];





    NSLog( @"copy create database");
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"sucess" message:@"COPY CAT DB" delegate:self cancelButtonTitle:@"dismis" otherButtonTitles:nil, nil];
    [alert show];
}else{
    NSLog( @"Failed to open/create database");

}



}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM