Sample code for 30+ languages & platforms
Objective-C

Zip a Directory Tree

See more Zip Examples

Demonstrates how to zip an entire directory tree into a .zip archive.

Chilkat Objective-C Downloads

Objective-C
#import <CkoZip.h>

BOOL success = NO;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

CkoZip *zip = [[CkoZip alloc] init];

success = [zip NewZip: @"test.zip"];
if (success != YES) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

//  Append a directory tree.  The call to AppendFiles does
//  not read the file contents or append them to the zip
//  object in memory.  It simply appends references
//  to the files so that when WriteZip or WriteZipAndClose 
//  is called, the referenced files are streamed and compressed
//  into the .zip output file.

BOOL recurse = YES;
success = [zip AppendFiles: @"c:/temp/a/*" recurse: recurse];
if (success != YES) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

success = [zip WriteZipAndClose];
if (success != YES) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

NSLog(@"%@",@"Zip Created!");