PoshCode Archive  Artifact [9e561fee2f]

Artifact 9e561fee2f876567ce5c584e938b398f6d7ff9853c70f61b0fa25a22172a7c14:

  • File Expand-ZipFile.ps1 — part of check-in [e3b82cc121] at 2018-06-10 14:03:47 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: 5905
# x-archived: 2015-06-26T07:16:50
# x-published: 2015-06-24T13:40: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
    }
}