0

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.

Sudha
  • 9
  • 9

2 Answers2

0

Use NSFileManager methods to inspect contents of unzip file. Try with

 - enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:

for a deep enumeration.

Or

 -contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:

for a shallow enumeration of contents.

Then you can filter files using extension to find images.

Gabriel
  • 3,319
  • 1
  • 16
  • 21
0

Use

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

to get the directory listing.

You will get your subfolder name from directoryContent array.

yoshiiiiiiii
  • 953
  • 8
  • 20