Sample code for 30+ languages & platforms
PowerShell

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

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

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

$zip = New-Object Chilkat.Zip

$success = $zip.OpenZip("my_files.zip")
if ($success -eq $false) {
    $($zip.LastErrorText)
    exit
}

$unzipDir = "/temp/unzipDir"

# Get the number of files and directories in the .zip
$n = $zip.NumEntries

$entry = New-Object Chilkat.ZipEntry

$i = 0
while ($i -lt $n) {

    $zip.EntryAt($i,$entry)
    if ($entry.IsDirectory -eq $false) {
        # (the filename may include a path)
        $($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 -eq $false) {
            $($entry.LastErrorText)
            exit
        }

    }

    $i = $i + 1
}