2015-02-10 203 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數組中獲取您的子文件夾名稱。