I have successfully downloaded zip file and unzip it with the help of ZipArchive
. But now I have to access images from sub-folder of unzip file. The unzip folder is saved in document directory. Sub folder name always changed. I have used following code to unzip the zip file :
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);
}
Please help me out. Thanks in advance.