-
-
Save arlm/d4ee5b5c5b77cc59a66ff7d10768d774 to your computer and use it in GitHub Desktop.
Unzip a file in powershell by overwriting existing files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Unzip($zipfile, $outdir) | |
{ | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
$archive = [System.IO.Compression.ZipFile]::OpenRead($zipfile) | |
foreach ($entry in $archive.Entries) | |
{ | |
$entryTargetFilePath = [System.IO.Path]::Combine($outdir, $entry.FullName) | |
$entryDir = [System.IO.Path]::GetDirectoryName($entryTargetFilePath) | |
#Ensure the directory of the archive entry exists | |
if(!(Test-Path $entryDir )){ | |
New-Item -ItemType Directory -Path $entryDir | Out-Null | |
} | |
#If the entry is not a directory entry, then extract entry | |
if(!$entryTargetFilePath.EndsWith("\")){ | |
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $entryTargetFilePath, $true); | |
} | |
} | |
} | |
Unzip -zipfile "$zip" -outdir "$dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment