« Procedurally Generated WebGL Trees with SnappyTree | Main | Zip up a Folder with .NET 4.5 and Visual Studio 2012 »
Friday
Aug172012

Zip up a Folder with PowerShell 3 the Easy Way  

My previous post showed how to do this with C# and Visual Studio. Because PowerShell 3 in Windows 8 uses the .NET 4.5 CLR we can use the same technique to create a ZIP file without relying on external libraries or tools.

The script is straightforward. Just load the System.IO.Compression.FileSystem assembly and call[System.IO.Compression.ZipFile]::CreateFromDirectory().


[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
$src_folder = "D:\stuff"
$destfile = "D:\stuff.zip"
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
$includebasedir = $false
[System.IO.Compression.ZipFile]::CreateFromDirectory($src_folder,$destfile,$compressionLevel, $includebasedir )

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (2)

Hi

Thanks for this post. Just a question about this: Are there any size limits of the zip file with this method?

Regards

March 20, 2015 | Unregistered Commentermarius

@Marius - I haven't tried it with anything over 100MB - so I'm not sure what will happen if you try it with a many gigabytes of data.

March 28, 2015 | Registered Commentersaveenr

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>