我的方法适用于从先前创建和填充的临时目录中压缩文件:
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];
但是解压后我想要的是一个包含文件的文件夹。 当然我可以在 tempDir 中创建一个文件夹并在那里写入我的文件,但是让文件夹成为创建的存档中的顶层的 zip 参数是什么?
我在 man zip
中没有看到这个。
最佳答案
这会对你有帮助。
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];
关于cocoa - 使用 NSTask 创建 zip 存档,其中包含包含文件的第一级文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5380262/