Tcl
Tcl
Unzip Some Files by Iterating over Entries
See more Zip Examples
Demonstrates how to unzip specific files by iterating over entries in a .zip.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set zip [new_CkZip]
# Open a .zip containing:
#
# a1.xml
# b1.xml
# c1.xml
# dir1/a2.xml
# dir1/c2.xml
# dir2/dir3/c3.xml
# We wish to unzip only a1.xml, b1.xml, and c1.xml
set success [CkZip_OpenZip $zip "qa_data/zips/xml_files.zip"]
if {$success == 0} then {
puts [CkZip_lastErrorText $zip]
delete_CkZip $zip
exit
}
set sbFilename [new_CkStringBuilder]
set entry [new_CkZipEntry]
set numEntries [CkZip_get_NumEntries $zip]
set i 0
while {$i < $numEntries} {
CkZip_EntryAt $zip $i $entry
set entryFilePath [CkZipEntry_fileName $entry]
puts "$entryFilePath"
if {[CkZipEntry_get_IsDirectory $entry] == 0} then {
CkStringBuilder_SetString $sbFilename $entryFilePath
if {[CkStringBuilder_Contains $sbFilename "/" 0] == 0} then {
# Does not contain "/"
# Unzip to the qa_output directory.
set success [CkZipEntry_Extract $entry "qa_output"]
if {$success == 0} then {
puts "Failed to unzip $entryFilePath"
} else {
puts "Unzipped $entryFilePath"
}
}
}
set i [expr $i + 1]
}
delete_CkZip $zip
delete_CkStringBuilder $sbFilename
delete_CkZipEntry $entry