This topic demonstrates how to unzip files using the static Unzip method of the QuickZip class.
When unzipping the contents of a spanned zip file, the last disk must be in the drive before the operation begins.
The Unzip method has various overloads that can be used to unzip files. Some only require that you specify the zip file and the files you want to extract while others let you decide on a number of other factors among which are the possibility to decrypt encrypted files and unzip files from split or spanned zip files.
In the following example, we will unzip the contents of a regular zip file:
VB.NET | Copy Code |
---|---|
QuickZip.Unzip( "d:\test.zip", "d:\", True, True, False, "*" ) |
C# | Copy Code |
---|---|
|
In the next example, we will extract the contents of a spanned, self-extracting zip file:
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
When extracting files from within a zip file, the directory structure can be restored fully or partrially or it can be omitted altogether.
If the preservePaths parameter of the Unzip method is set to false, the files specified in the filesToUnzip parameter will be restored directly into the root of the destination folder without recreating the directory structure.
For example, if you have a zip file containing files in the "folder1" subfolder and files in the "folder1\folder2" subfolder, the following code will unzip all files right into "c:\temp", without creating any subfolders:
VB.NET | Copy Code |
---|---|
Xceed.Zip.QuickZip.Unzip( "c:\test.zip", "c:\temp", True, True, False, "folder1\*" ) |
C# | Copy Code |
---|---|
Xceed.Zip.QuickZip.Unzip( @"c:\test.zip", @"c:\temp", true, true, false, @"folder1\*" ); |
If the preservePaths parameter is set to true, the part of the path that is explicitly included in the filesToUnzip parameter will not be restored into the destination folder.
For example, for the same zip file as above, the following code will create the folder "folder2" into the "c:\temp" destination folder. Files that were in the "folder1" subfolder in the zip will be unzipped directly into the root of "c:\temp", and files that were in "folder1\folder2" will be unzipped into "c:\temp\folder2":
VB.NET | Copy Code |
---|---|
Xceed.Zip.QuickZip.Unzip( "c:\test.zip", "c:\temp", True, True, True, "folder1\*" ) |
C# | Copy Code |
---|---|
Xceed.Zip.QuickZip.Unzip( @"c:\test.zip", @"c:\temp", true, true, true, @"folder1\*" ); |
The following example will unzip files into "c:\temp\folder1" and "c:\temp\folder1\folder2":
VB.NET | Copy Code |
---|---|
Xceed.Zip.QuickZip.Unzip( "c:\test.zip", "c:\temp", True, True, True, "*" ) |
C# | Copy Code |
---|---|
Xceed.Zip.QuickZip.Unzip( @"c:\test.zip", @"c:\temp", true, true, true, @"*" ); |
Note that the filesToUntar parameter of the Untar method cannot be null; otherwise, an ArgumentNullException exception will be thrown.
The main questions you should ask yourself when extracting files from a Tar archive are:
Do you want to do more complex Tar archive operations? Use the FileSystem-based classes defined within the Xceed.Tar.