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 wri开发者_运维技巧te 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
.
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];
instead of using NSTask
, you could incorporate compress functionality into your code. there are several options.
- ZipBrowser from apple.com
- adding a category to
NSData
, as in here - a similar question. How can I create a zip file by using Objective C?
精彩评论