Dart
Dart
Zip a Directory Tree
See more Zip Examples
Demonstrates how to zip an entire directory tree into a .zip archive.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final zip = CkZip();
try {
zip.newZip('test.zip');
} on ChilkatException catch (e) {
print(e.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.
final recurse = true;
try {
zip.appendFiles('c:/temp/a/*', recurse);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
zip.writeZipAndClose();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Zip Created!');
}