Skip to content

Convert-Dir2zip

Converts a directory into a compressed .ZIP file

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: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the path to the directory

Specifies the path to the target .ZIP file (default is dirPath.zip)

An interactive directory of PowerShell scripts.