Go
Go
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 Go Downloads
success := false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip := chilkat.NewZip()
success = zip.OpenZip("my_files.zip")
if success == false {
fmt.Println(zip.LastErrorText())
zip.DisposeZip()
return
}
unzipDir := "/temp/unzipDir"
// Get the number of files and directories in the .zip
n := zip.NumEntries()
entry := chilkat.NewZipEntry()
i := 0
for i < n {
zip.EntryAt(i,entry)
if entry.IsDirectory() == false {
// (the filename may include a path)
fmt.Println(entry.FileName())
// Your application may choose to unzip this entry
// based on the filename.
// If the entry should be unzipped, then call Extract(unzipDir)
success = entry.Extract(unzipDir)
if success == false {
fmt.Println(entry.LastErrorText())
zip.DisposeZip()
entry.DisposeZipEntry()
return
}
}
i = i + 1
}
zip.DisposeZip()
entry.DisposeZipEntry()