PoshCode Archive  Artifact [a0d94d2567]

Artifact a0d94d2567cd9c141bf8d69936d03a7b9156fb527b00f60cb13b5cdfcc1587b1:

  • File Expand-ZipFile.ps1 — part of check-in [e27f50573e] at 2018-06-10 13:25:05 on branch trunk — Extracts the contents of a ZIP file to a folder (user: Thomas Freudenbe size: 1309)

# encoding: ascii
# api: powershell
# title: Expand-ZipFile
# description: Extracts the contents of a ZIP file to a folder
# version: 0.1
# type: function
# author: Thomas Freudenbe
# license: CC0
# function: Expand-ZipFile
# x-poshcode-id: 3400
# x-archived: 2016-10-25T21:31:47
# x-published: 2012-05-06T10:17:00
#
#
function Expand-ZipFile {
    param {
       $zipPath,
       $destination,
       [switch] $quiet
    }

    $shellApplication = new-object -com shell.application
    $zipPackage = $shellApplication.NameSpace($zipPath)
    $destinationFolder = $shellApplication.NameSpace($destination) 

    # CopyHere vOptions Flag # 4 - Do not display a progress dialog box. 
    # 16 - Respond with "Yes to All" for any dialog box that is displayed. 
    #$destinationFolder.CopyHere($zipPackage.Items(),20) 
    $total = $zipPackage.Items().Count
    $progress = 1;
    foreach ($zipFile in $zipPackage.Items()) {
        if(!$quiet) {
            Write-Progress "Extracting $zipPath" "Extracting $($zipFile.Name)" -id 0 -percentComplete (($progress/$total)*100)        
        }

        $destinationFolder.CopyHere($zipFile,20) 
        $progress++
    }
    if(!$quiet) {
        Write-Progress "Extracted $zipPath" "Extracted $total items" -id 0
    }
}