2015-02-10 185 views
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); 
    } 

请帮我。 在此先感谢。

回答

0

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

- enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: 

深入枚举。

或者

-contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error: 

为内容的浅枚举。

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

0

使用

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

获得目录列表。

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