Dart Requires Chilkat v11.0.0+
Dart
Unzip Selected Files from a Zip Archive
See more Zip Examples
Demonstrates how to iterate over the files contained within a .zip and unzip specific files.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.openZip('my_files.zip');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final unzipDir = '/temp/unzipDir';
// Get the number of files and directories in the .zip
final n = zip.numEntries;
final entry = CkZipEntry();
var i = 0;
while (i < n) {
zip.entryAt(i, entry);
if (!entry.isDirectory) {
// (the filename may include a path)
print(entry.fileName);
// Your application may choose to unzip this entry
// based on the filename.
// If the entry should be unzipped, then call Extract(unzipDir)
try {
entry.extract(unzipDir);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}
i++;
}
}