PoshCode Logo PowerShell Code Repository

Difference between
modified post 6839 by mr64bit on Wed 12th Apr 18:21 and
original post 5668 by JayneticMuffin on Wed 7th Jan 14:13
Showold version | new version | both versions

    
11
# Unzip the file and keep the zip
22
# Unzip-File -FileName 'test.zip'
33
# Unzip the file and delete the zip
44
# Unzip-File -FileName 'test.zip' -DeleteSource $True
55
function Unzip-File {
66
	param (
77
		[parameter(mandatory=$true][ValidateNotNullOrEmpty()]$fileName,
88
		$DeleteSource = $false
99
	)
1010
	$fileInfo = Get-Item -Path $FileName
1111
	$appName = New-Object -ComObject Shell.Application
1212
	$zipName = $appName.NameSpace($fileInfo.FullName)
1313
	$extPath = $fileInfo.Directory.FullName + '\' + $fileInfo.BaseName
1414
	$null = New-Item -Path $extPath -ItemType Directory -Force
1515
	$dstFolder = $appName.NameSpace($extPath)
1616
	$dstFolder.Copyhere($zipName.Items())
1717
	If ($DeleteSource) {Remove-Item -Path $fileInfo.FullName}
1818
}
1919
function Unzip-MultipleFiles {
2020
	param (
2121
		[parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string]$Path,
2222
		$DeleteSource = $false
2323
	)
2424
	$Files = Get-ChildItem -Path $Path -Recurse -Include '*.zip' | Select FullName,Directory,BaseName
2525
	$Files | % {
2626
		Unzip-File -FileName $_.FullName
2727
		If ($DeleteSource) {Remove-Item -Path $_.FullName}
2828
	}
2929
}

ContributeMost Recent Contributions (feed)

Contribute ... Next Page