0

我已经成功下载了 zip 文件并在ZipArchive. 但是现在我必须从解压缩文件的子文件夹中访问图像。解压缩文件夹保存在文档目录中。子文件夹名称总是改变。我使用以下代码解压缩 zip 文件:

    NSURL *zipUrl = [NSURL URLWithString:responseString];
    NSData *data = [NSData dataWithContentsOfURL:zipUrl options:0 error:&error];
    if(!error)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSLog(@"paths..%@",paths);
        NSString *path = [paths objectAtIndex:0];
        NSString *zipPath = [path stringByAppendingPathComponent:@"zipfile.zip"];

        [data writeToFile:zipPath options:0 error:&error];

        if(!error)
        {
            ZipArchive *za = [[ZipArchive alloc] init];
            if ([za UnzipOpenFile: zipPath])
            {
                BOOL ret = [za UnzipFileTo: path overWrite: YES];
                if (NO == ret){} [za UnzipCloseFile];
            }
        }
        else
        {
            NSLog(@"Error saving file %@",error);
        }
    }
    else
    {
        NSLog(@"Error downloading zip file: %@", error);
    }

请帮帮我。提前致谢。

4

2 回答 2

0

使用 NSFileManager 方法检查解压缩文件的内容。尝试

 - enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:

进行深入的枚举。

或者

 -contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:

用于内容的浅层枚举。

然后,您可以使用扩展名过滤文件以查找图像。

于 2015-02-10T09:53:59.910 回答
0

利用

NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];

获取目录列表。

您将从 directoryContent 数组中获取您的子文件夹名称。

于 2015-02-17T10:43:13.467 回答