ZipFile
This can compress an entire directory. It then can expand the compressed file into a new directory. We use the CreateFromDirectory
and ExtractToDirectory
methods.
ZipFile
is simpler than developing custom methods. The code is heavily-tested, as it is part of .NET, so less development burden is created.
To use this program, please create a folder called "source" in the same directory as the program executable. You can add files to it.
destination.zip
" into a folder called "destination." We specify CompressionLevel.Optimal
.Imports System.IO.Compression Module Module1 Sub Main() ' Create ZIP from "source" directory (in program folder). ZipFile.CreateFromDirectory("source", "destination.zip", CompressionLevel.Optimal, False) ' Extract ZIP to "destination" folder. ZipFile.ExtractToDirectory("destination.zip", "destination") End Sub End Module
You may need to add a reference in Visual Studio. Go to Add Reference and select System.IO.Compression.FileSystem
. ZipFile
was not in the older versions of .NET.
The Optimal compression level helps reduce the size of the archive. But Optimal will likely cause the program to slow down.
We used the ZipFile
type in VB.NET. We compressed all the files in one directory into a single ZIP file. We then expanded that file into the original form.