tags:

views:

56

answers:

2

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??
A: 

You can access it with NSFileManager's

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

tob
this unzip code is not working on phone daamm :( i need a working unzip code plz help
ram
A: 

Hi Ram , to unzip file on iphone read this - http://www.touch-code-magazine.com/update-dynamically-your-iphone-app-with-new-content/

Abhijeet Barge
wow thanks a lot you saved my life :-)
ram