1

I am using Objective Zip for unzipping a Zipped file and saving to document directory. The unzipping works fine. The individual files in in the zipped file can be written perfectly to the documents directory.

The problem is I cannot write the Sub Folders inside the Zip file as Folders to the documents directory. It is shown as text files with no content.

How can I solve this ? How can I write the folders as Folders to the directory?

below is the code I've used.

    NSString *targetFolder = docPath; // Path to Document directory
    [unzipFile goToFirstFileInZip];


    for (NSString *file in fileArray) {


      ZipReadStream *readStream = [unzipFile readCurrentFileInZip];
      FileInZipInfo *fileInfo = [unzipFile getCurrentFileInZipInfo];
      NSString *fileName = [fileInfo name];


      NSLog(@"File Name--- %@",fileName);
      NSString *unzipFilePath = [targetFolder stringByAppendingPathComponent:fileName];


    if (![fileManager fileExistsAtPath:unzipFilePath]) {
        [fileManager createFileAtPath:unzipFilePath contents:nil attributes:nil];
    }
TheCodingArt
  • 3,436
  • 4
  • 30
  • 53
Abhijith
  • 3,094
  • 1
  • 33
  • 36

1 Answers1

0

You have to create the directories before you can write into them

for example with

NSString *dir = [unzipFilePath stringByDeletingLastPathComponent];
if (![fileManager fileExistsAtPath:dir isDirectory:nil]) {
    [fileManager createDirectoryAtPath:dir attributes:nil];
    NSLog(@"created directory %@", dir);
}
Bastian
  • 10,403
  • 1
  • 31
  • 40