Question

my method works for zipping files from a temporary directory previously created and populated:

NSURL *destURL = self.archiveDestURL;
NSTask *task = [[NSTask alloc] init];
[task setCurrentDirectoryPath:[srcURL path]]; 
[task setLaunchPath:@"/usr/bin/zip"];
NSArray *argsArray = [NSArray arrayWithObjects:@"-r", @"-q", [destURL path], @".", @"-i", @"*", nil];
[task setArguments:argsArray];
[task launch];
[task waitUntilExit];

but what i'd like to have when unzipped, is a folder with the files. sure i can make a folder in the tempDir and write my files there, but what is the zip argument for having a folder be the top level in the created archive?

i didn't see this in man zip .

Was it helpful?

Solution

This will help you.

NSTask *unzip = [[NSTask alloc] init];
[unzip setLaunchPath:@"/usr/bin/unzip"];
[unzip setArguments:[NSArray arrayWithObjects:@"-u", @"-d", 
                     destination, zipFile, nil]];

NSPipe *aPipe = [[NSPipe alloc] init];
[unzip setStandardOutput:aPipe];

[unzip launch];
[unzip waitUntilExit];

OTHER TIPS

instead of using NSTask, you could incorporate compress functionality into your code. there are several options.

  1. ZipBrowser from apple.com
  2. adding a category to NSData, as in here
  3. a similar question. How can I create a zip file by using Objective C?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top