Sample code for 30+ languages & platforms
B4X Requires Chilkat v11.0.0+

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 B4X Downloads

B4X
Dim success As Boolean = False

'  This example requires the Chilkat API to have been previously unlocked.
'  See Global Unlock Sample for sample code.

Dim zip As ChilkatZip
zip.Initialize("zip")

success = zip.OpenZip("my_files.zip")
If success = False Then
    Log(zip.LastErrorText)
    Return
End If


Dim unzipDir As String = "/temp/unzipDir"

'  Get the number of files and directories in the .zip
Dim n As Int = zip.NumEntries

Dim entry As ChilkatZipEntry
entry.Initialize("entry")

Dim i As Int = 0
Do While i < n

    zip.EntryAt(i, entry)
    If entry.IsDirectory = False Then
        '  (the filename may include a path)
        Log(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 Then
            Log(entry.LastErrorText)
            Return
        End If


    End If

    i = i + 1
Loop