From 4e2065b6bb4b42e1a7bc2fad811c6894550b1555 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 12 Nov 2021 11:09:52 -0500 Subject: [PATCH] add destination parameter --- Tools.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tools.ps1 b/Tools.ps1 index 069060c..1284313 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -539,9 +539,13 @@ function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) { } # Function to ZIP a file or directory -function Zip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) { +function Zip-Object { + param( + [Parameter(ValueFromPipeline=$true)][string]$path, + [Parameter(ValueFromPipeline=$false)][string]$dest + ) If ( $(Get-Item $path) -is [System.IO.DirectoryInfo] ) { - $dest = '{0}\{1}.zip' -f $(Split-Path -Parent $path),$(Split-Path -Leaf $path) + If ( [string]::IsNullOrEmpty($dest) ) { $dest = '{0}\{1}.zip' -f $(Split-Path -Parent $path),$(Split-Path -Leaf $path) } LogMsg "Creating zip file of: ${path}" Try { Add-Type -Assembly "System.IO.Compression.FileSystem" @@ -566,10 +570,9 @@ function Zip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) { # Function to UNZIP a file or directory function Unzip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) { - $ext = [System.IO.Path]::GetExtension($path) - If ( $ext -eq ".zip" ) { - LogMsg "Extracting ""${path}"" to ""${dest}""" + If ( [System.IO.Path]::GetExtension($path) -eq ".zip" ) { $dest = Split-Path -Parent $path + LogMsg "Extracting ""${path}"" to ""${dest}""" Try { Add-Type -Assembly "System.IO.Compression.FileSystem" [IO.Compression.ZipFile]::ExtractToDirectory($path, $dest)