(Objective-C) Zip a Directory Tree
Demonstrates how to zip an entire directory tree into a .zip archive.
#import <CkoZip.h>
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoZip *zip = [[CkoZip alloc] init];
BOOL 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!");
|