# encoding: ascii
# api: powershell
# title: Unzip Files
# description: Wanted to create an unzip function for single files with an option to delete the originating zip, and also have a function for scanning through a folder structure recursively and providing the same functionality… and here it is.
# version: 0.1
# type: function
# author: JayneticMuffin
# license: CC0
# function: Unzip-File
# x-poshcode-id: 5668
# x-archived: 2017-04-17T14:38:33
# x-published: 2017-01-07T14:13:00
#
#
# Unzip the file and keep the zip
# Unzip-File -FileName 'test.zip'
# Unzip the file and delete the zip
# Unzip-File -FileName 'test.zip' -DeleteSource $True
function Unzip-File {
	param (
		[parameter(mandatory=$true][ValidateNotNullOrEmpty()]$fileName,
		$DeleteSource = $false
	)
	$fileInfo = Get-Item -Path $FileName
	$appName = New-Object -ComObject Shell.Application
	$zipName = $appName.NameSpace($fileInfo.FullName)
	$extPath = $fileInfo.Directory.FullName + '\' + $fileInfo.BaseName
	$null = New-Item -Path $extPath -ItemType Directory -Force
	$dstFolder = $appName.NameSpace($extPath)
	$dstFolder.Copyhere($zipName.Items())
	If ($DeleteSource) {Remove-Item -Path $fileInfo.FullName}
}
function Unzip-MultipleFiles {
	param (
		[parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string]$Path,
		$DeleteSource = $false
	)
	$Files = Get-ChildItem -Path $Path -Recurse -Include '*.zip' | Select FullName,Directory,BaseName
	$Files | % {
		Unzip-File -FileName $_.FullName
		If ($DeleteSource) {Remove-Item -Path $_.FullName}
	}
}
