1

我正在创建文件夹的 zip 文件我想知道如何从 zip 中删除 sqlite 文件我只需要 zip 中的其他文件但它会将文件夹目录中保存的所有文件都提供给 zip 我不希望 zip 文件中的 sqlite 文件

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDirectory = [paths objectAtIndex:0];
    BOOL isDir=NO;
    NSArray *subpaths;
    NSString *exportPath = docDirectory;
    NSFileManager *fileManager = [NSFileManager defaultManager];    
    if ([fileManager fileExistsAtPath:exportPath isDirectory:&isDir] && isDir){
        subpaths = [fileManager subpathsAtPath:exportPath];
    }

    NSString *archivePath = [docDirectory stringByAppendingString:@".zip"];

    ZipArchive *archiver = [[ZipArchive alloc] init];
    [archiver CreateZipFile2:archivePath];
    for(NSString *path in subpaths)
    {
        NSString *longPath = [exportPath stringByAppendingPathComponent:path];
        if([fileManager fileExistsAtPath:longPath isDirectory:&isDir] && !isDir)
        {
            [archiver addFileToZip:longPath newname:path];      
        }
    }
    BOOL successCompressing = [archiver CloseZipFile2];
    if(successCompressing)
        NSLog(@"Success");
    else
        NSLog(@"Fail");





    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;




    NSString *emailBody =@""; 
    [picker setMessageBody:emailBody isHTML:NO];

    [picker addAttachmentData:myData mimeType:@"" fileName:@"Document.Zip"];
4

1 回答 1

0

您要做的是使用 dataWithContentsOfFile: 创建一个 NSData 对象,并带有一个 zip 存档的路径,然后将 mime 类型设置为 application/zip。

于 2012-06-04T06:24:29.013 回答