add destination parameter

This commit is contained in:
2021-11-12 11:09:52 -05:00
parent 5b6fd565b9
commit 4e2065b6bb
+8 -5
View File
@@ -539,9 +539,13 @@ function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
} }
# Function to ZIP a file or directory # 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] ) { 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}" LogMsg "Creating zip file of: ${path}"
Try { Try {
Add-Type -Assembly "System.IO.Compression.FileSystem" 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 to UNZIP a file or directory
function Unzip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) { function Unzip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) {
$ext = [System.IO.Path]::GetExtension($path) If ( [System.IO.Path]::GetExtension($path) -eq ".zip" ) {
If ( $ext -eq ".zip" ) {
LogMsg "Extracting ""${path}"" to ""${dest}"""
$dest = Split-Path -Parent $path $dest = Split-Path -Parent $path
LogMsg "Extracting ""${path}"" to ""${dest}"""
Try { Try {
Add-Type -Assembly "System.IO.Compression.FileSystem" Add-Type -Assembly "System.IO.Compression.FileSystem"
[IO.Compression.ZipFile]::ExtractToDirectory($path, $dest) [IO.Compression.ZipFile]::ExtractToDirectory($path, $dest)