简体   繁体   中英

i can unzip the folder but how to access that folder form iphone

this code allows you to unzip file and create a folder in documents lets say List and this List folder is having all the unzip data now how to access that List content ??

     NSArray *paths = 
     NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

     NSString *documentsDirectory = [paths objectAtIndex:0];

     NSString *saveLocation = 
     [documentsDirectory stringByAppendingString:@"myfile.zip"];

     NSFileManager* fileManager = [NSFileManager defaultManager];

     if ([fileManager fileExistsAtPath:saveLocation]) {
         [fileManager removeItemAtPath:saveLocation error:nil];
         NSLog(@" file path %@",fileManager);
     }

     NSURLRequest *theRequest = 
     [NSURLRequest requestWithURL:
      [NSURL URLWithString:@"http://localhost/list.zip"]
                      cachePolicy:NSURLRequestUseProtocolCachePolicy
                  timeoutInterval:60.0];    

     NSData *received = 
     [NSURLConnection sendSynchronousRequest:theRequest
                           returningResponse:nil error:nil];    

     if ([received writeToFile:saveLocation atomically:TRUE]) {      
         NSString *cmd = 
         [NSString stringWithFormat:@"unzip \"%@\" -d\"%@\"", 
          saveLocation, documentsDirectory];       

         // Here comes the magic...
         system([cmd UTF8String]);       
     }


     NSLog(@"loca is %@", saveLocation);


      NSLog(@"%@", [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil]);  // i can see list folder but how to get the content outside??

在iPhone上解压缩文件,请阅读以下内容-http: //www.touch-code-magazine.com/update-dynamically-your-iphone-app-with-new-content/

You can access it with NSFileManager 's

- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM