Create a zip archive using NSTask containing a first-level folder with files

my method works for zipping files from the created and entered temporary directory:

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 would like to have when unpacking is a folder with files. Of course, I can create a folder in tempDir and write my files there, but what is the zip argument so that the folder is the top level in the created archive?

I have not seen this in man zip .

+4
source share
2 answers

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]; 
+3
source

instead of NSTask , you can include compression functions in your code. There are several options.

0
source

Source: https://habr.com/ru/post/1344628/


All Articles