开发者

create zip archive using NSTask containing a first level folder with the files

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.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜