DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoZip
String sUnzipDir
Integer n
Variant vEntry
Handle hoEntry
Integer i
String sTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatZip)) To hoZip
If (Not(IsComObjectCreated(hoZip))) Begin
Send CreateComObject of hoZip
End
Get ComOpenZip Of hoZip "my_files.zip" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
Move "/temp/unzipDir" To sUnzipDir
// Get the number of files and directories in the .zip
Get ComNumEntries Of hoZip To n
Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
If (Not(IsComObjectCreated(hoEntry))) Begin
Send CreateComObject of hoEntry
End
Move 0 To i
While (i < n)
Get pvComObject of hoEntry to vEntry
Get ComEntryAt Of hoZip i vEntry To iSuccess
Get ComIsDirectory Of hoEntry To bTemp1
If (bTemp1 = False) Begin
// (the filename may include a path)
Get ComFileName Of hoEntry To sTemp1
Showln sTemp1
// Your application may choose to unzip this entry
// based on the filename.
// If the entry should be unzipped, then call Extract(unzipDir)
Get ComExtract Of hoEntry sUnzipDir To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEntry To sTemp1
Showln sTemp1
Procedure_Return
End
End
Move (i + 1) To i
Loop
End_Procedure