Created
October 3, 2018 19:11
-
-
Save DanielMPries/d0a8d8abebae6fccf1cb31f8f0ac340e to your computer and use it in GitHub Desktop.
Compress all of the files in a given path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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