Skip to content

Instantly share code, notes, and snippets.

@hanzelkatomas
Last active March 19, 2025 14:57
Show Gist options
  • Select an option

  • Save hanzelkatomas/e6959fe188ec6d7c974b084c4b4b0fbb to your computer and use it in GitHub Desktop.

Select an option

Save hanzelkatomas/e6959fe188ec6d7c974b084c4b4b0fbb to your computer and use it in GitHub Desktop.
Unzip all files from source directory to target directory
# Usage:
# .\extract-zips.ps1 -SourceDir "C:\path\to\zipfiles" -DestinationDir "C:\path\to\destination"
param(
[Parameter(Mandatory=$true)]
[string]$SourceDir,
[Parameter(Mandatory=$true)]
[string]$DestinationDir
)
# Ensure the source directory exists
if (-not (Test-Path -Path $SourceDir)) {
Write-Error "Source directory does not exist: $SourceDir"
exit 1
}
# Create the destination directory if it doesn't exist
if (-not (Test-Path -Path $DestinationDir)) {
New-Item -Path $DestinationDir -ItemType Directory | Out-Null
Write-Host "Created destination directory: $DestinationDir"
}
# Get all zip files from the source directory
$zipFiles = Get-ChildItem -Path $SourceDir -Filter "*.zip"
if ($zipFiles.Count -eq 0) {
Write-Host "No zip files found in: $SourceDir"
exit 0
}
Write-Host "Found $($zipFiles.Count) zip file(s) to extract..."
# Extract each zip file to the destination directory
foreach ($zip in $zipFiles) {
Write-Host "Extracting: $($zip.Name)..."
# Using the built-in Expand-Archive cmdlet (PowerShell 5.0+)
Expand-Archive -Path $zip.FullName -DestinationPath $DestinationDir -Force
}
Write-Host "All zip files have been extracted to: $DestinationDir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment