unzipping a file in cocoa

后端 未结 7 1165
长发绾君心
长发绾君心 2020-12-18 01:59

I have a zipped file, which i want to extract the contents of it. What is the exact procedure that i should do to achieve it. Is there any framework to unzip the files in co

7条回答
  •  情书的邮戳
    2020-12-18 02:12

    Here's a more concise version based on codingFriend1's approach

    + (void)unzip {
        NSString *targetFolder = @"/tmp/unzipped";
        NSString* zipPath = @"/path/to/my.zip";
        NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/unzip" arguments:@[@"-o", zipPath, @"-d", targetFolder]];
        [task waitUntilExit];
    }
    

    -d specifies the destination directory, which will be created by unzip if not existent

    -o tells unzip to overwrite existing files (but not to deleted outdated files, so be aware)

    There's no error checking and stuff, but it's an easy and quick solution.

提交回复
热议问题