Skip to content

Instantly share code, notes, and snippets.

@DanielMPries
Created October 3, 2018 19:11
Show Gist options
  • Save DanielMPries/d0a8d8abebae6fccf1cb31f8f0ac340e to your computer and use it in GitHub Desktop.
Save DanielMPries/d0a8d8abebae6fccf1cb31f8f0ac340e to your computer and use it in GitHub Desktop.
Compress all of the files in a given path
# This is the old way, use Compress-Archive
Add-Type -assembly "system.io.compression.filesystem"
$source = Get-ChildItem -Path "c:\stuff" -Directory
Write-Host "$($source.length) files found"
Foreach ($s in $source) {
Write-Host "Writing $($s.name).zip..."
$destination = Join-path -path "C:\stuff" -ChildPath "$($s.name).zip"
If(Test-path $destination) {
Remove-item $destination
}
[io.compression.zipfile]::CreateFromDirectory($s.fullname, $destination)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment