PoshCode Archive  Artifact [4b9f237bc6]

Artifact 4b9f237bc62f886c2b55c350038b8dcb7bad89c525314f13212222e401591dd9:

  • File Global-Zip-functions.ps1 — part of check-in [7f5687368b] at 2018-06-10 14:03:49 on branch trunk — Extract-zip got me thinking – I’ve had some global Zip functions in my .profile for a long ass time – here they are, I suggest if you want to allow “global” use of these, to add them to the global profile for powershell. I’m sure I copied them form some PS guru, but the whom escapes me… (user: Munsonisim size: 2047)

# encoding: ascii
# api: powershell
# title: Global Zip functions
# description: Extract-zip got me thinking – I’ve had some global Zip functions in my .profile for a long ass time – here they are, I suggest if you want to allow “global” use of these, to add them to the global profile for powershell. I’m sure I copied them form some PS guru, but the whom escapes me…
# version: 0.1
# type: function
# author: Munsonisim
# license: CC0
# x-poshcode-id: 5906
# x-archived: 2015-06-26T07:15:12
# x-published: 2015-06-24T15:09:00
#
# Included: New-Zip, Add-Zip, Get-Zip, and finally Extract-Zip
#
# Zip functions, We can NEW, ADD, LIST, and EXTRACT 
# Pipeline input accepted
# Example: dir <Path to files> | add-zip <Path to Destination Zipfile>
function global:New-Zip
{
	param([string]$zipfilename)
	set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
	(dir $zipfilename).IsReadOnly = $false
}
function global:Add-Zip
{
	param([string]$zipfilename)

	if(-not (test-path($zipfilename)))
	{
		set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
		(dir $zipfilename).IsReadOnly = $false	
	}
	
	$shellApplication = new-object -com shell.application
	$zipPackage = $shellApplication.NameSpace($zipfilename)
	
	foreach($file in $input) 
	{ 
            $zipPackage.CopyHere($file.FullName)
            Start-sleep -milliseconds 500
	}
}
function global:Get-Zip
{
	param([string]$zipfilename)
	if(test-path($zipfilename))
	{
		$shellApplication = new-object -com shell.application
		$zipPackage = $shellApplication.NameSpace($zipfilename)
		$zipPackage.Items() | Select Path
	}
}
function global:Extract-Zip
{
	param([string]$zipfilename, [string] $destination)

	if(test-path($zipfilename))
	{	
		$shellApplication = new-object -com shell.application
		$zipPackage = $shellApplication.NameSpace($zipfilename)
		$destinationFolder = $shellApplication.NameSpace($destination)
		$destinationFolder.CopyHere($zipPackage.Items())
	}
}