Renamed new-zipfile.ps1 to convert-dir2zip.ps1

This commit is contained in:
Markus Fleschutz 2024-07-15 14:57:20 +02:00
parent 6fdcf8de48
commit eb0112d799
2 changed files with 36 additions and 31 deletions

36
scripts/convert-dir2zip.ps1 Executable file
View File

@ -0,0 +1,36 @@
<#
.SYNOPSIS
Converts a directory into a compressed .ZIP file
.DESCRIPTION
This PowerShell script creates a new compressed .ZIP file from a directory (including subfolders).
.PARAMETER dirPath
Specifies the path to the directory
.PARAMETER zipPath
Specifies the path to the target .ZIP file (default is dirPath.zip)
.EXAMPLE
PS> ./convert-dir2zip.ps1 C:\Windows Win.zip
Converted into compressed Win.zip in 291s.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$dirPath = "", [string]$zipPath = "")
try {
if ($dirPath -eq "" ) { $dirPath = Read-Host "Enter the path to the folder" }
$StopWatch = [system.diagnostics.stopwatch]::startNew()
$dirPath = Resolve-Path $dirPath
if ($zipPath -eq "" ) { $zipPath = "$dirPath.zip" }
Compress-Archive -path $dirPath -destinationPath $zipPath
[int]$elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ Converted into compressed $zipPath in $($elapsed)s."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -1,31 +0,0 @@
<#
.SYNOPSIS
Creates a new .ZIP file from a folder (including subfolders)
.DESCRIPTION
This PowerShell script creates a new .ZIP file from a folder (including subfolders).
.PARAMETER folder
Specifies the path to the folder
.EXAMPLE
PS> ./new-zipfile.ps1 C:\Windows
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$folder = "")
try {
if ($folder -eq "" ) { $folder = read-host "Enter the path to the folder to zip" }
$StopWatch = [system.diagnostics.stopwatch]::startNew()
$folder = resolve-path $folder
compress-archive -path $folder -destinationPath $folder.zip
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ created zip file $($folder).zip in $Elapsed sec"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}