PoshCode Archive  Artifact [0a66d0fb62]

Artifact 0a66d0fb62d3f79e37f16373a31ba8d6198c72d921b655186c69c77a7dffb3fc:

  • File Unzip-Files.ps1 — part of check-in [b60933d48d] at 2018-06-10 13:58:53 on branch trunk — 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. (user: JayneticMuffin size: 1576)

# 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}
	}
}