4

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 .

lulu
  • 669
  • 10
  • 26

2 Answers2

3

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];
Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
0

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?
Community
  • 1
  • 1
Cesar A. Rivas
  • 1,355
  • 1
  • 10
  • 13
  • cesar, thanks for your suggestions. my app just needs to make a zip archive if the user chooses that option, not read one. sorry for not being clear about that, so i don't see the need to categorize `NSData` as in the link you've referenced (which also uses `NSTask`), or in ZipBrowser's case, create class files to handle things. i'm looking for the possibility of staying within the built-in library and thought someone might know the correct arguement to hand off to it. – lulu Mar 21 '11 at 17:09
  • by 'unzipping' i mean what the user sees when she double-clicks on the zip archive in the finder. – lulu Mar 21 '11 at 17:11