-
-
Notifications
You must be signed in to change notification settings - Fork 473
/
Copy pathconvert-dir2zip.ps1
executable file
·36 lines (31 loc) · 1.07 KB
/
convert-dir2zip.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}