zipArchive解压缩到iOS上的文档文件夹

时间:2012-05-23 17:44:42

标签: ios unzip ziparchive

我正在使用ZipArchive解压缩,但是它将zip的内容解压缩到以zip文件命名的文档的子目录,而不是直接进入我的文档文件夹。有谁知道我可以改变什么来确保它保存到我想要的目录?

-(void) unZipUpdateArchiveAtPath: (NSString *)zipPath {
NSLog(@"UNZIP Update PATH: %@", zipPath);
ZipArchive *zipArchive = [[ZipArchive alloc] init];
if ([zipArchive UnzipOpenFile:zipPath])
{
    if ([zipArchive UnzipFileTo:[self documentDirectory]  overWrite:YES])
    {
        NSLog(@"Archive unzip success");
        [zipArchive UnzipCloseFile];
    }
    else
    {
        NSLog(@"Failure to unzip archive");
    }
}
else
{
    NSLog(@"Failure to open archive");
}
}

#pragma mark - Application's Documents directory
-(NSString *)documentDirectory
{
    NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentDirectory = [documentDirectories objectAtIndex:0];
    NSLog(@"docDirectory IS  %@", documentDirectory);
    return documentDirectory;
}

1 个答案:

答案 0 :(得分:0)

您需要将自定义路径附加到文档目录。

[zipArchive UnzipFileTo:[[self documentDirectory] stringByAppendingPathComponent:@"My folder"] overWrite:YES];