我可以解压缩文件夹,但如何从iphone访问该文件夹

时间:2010-08-12 02:38:11

标签: iphone

此代码允许您解压缩文件并在文档中创建一个文件夹让我们说List和此List文件夹现在拥有所有解压缩数据如何访问列表内容 ??

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

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

您可以使用NSFileManager

访问它

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