Unzipping files using the free Info-Zip Unzip DLL with VB

Add the ability to interpret ZIP files to your application without needing third-party controls

Unzip Test Application

This article provides a fully featured unzip application written in VB, using the capabilities of the Info-ZIP Unzip DLL. The zip application demonstrates the abilities of the unzip DLL to handle all aspects of unzip operations - password protection, directory listing, including directories whilst unzipping, prompts for overwriting files - in fact everything you've come to expect when using tools like WinZIP (which isn't surprising, because WinZIP uses the same base code!)

The code also demonstrates some nice features such as capturing the Shell Browse for Folder Dialog to provide a powerful and user-friendly method for picking folders and using the Registry to store Most-Recently Used File Lists.

More usefully, perhaps, the unzipping code is wrapped up into a reusable class which you can incorporate into your own projects. So, without further ado...

Reusing the VB code - Quick Start

To get the simplest overview of the code, extract these two files from the Unzip Sample project:

  • cUnzip.cls
  • mUnzip.bas

Add these two files to a new project in VB, and then declare a WithEvents instance of the cUnzip class:

   Private WithEvents m_cUnzip As cUnzip

The simplest operation is to open and unzip a zip without password encryption. This is all you need to do:

   ' Set the zip file:
   m_cUnzip.ZipFile = sFIle

   ' Set the base folder to unzip to:
   m_cUnzip.UnzipFolder = sFolder

   ' Unzip the file!
   m_cUnzip.Unzip

In More Detail

Directory Listings

To get a directory of files within the zip, use the Directory method. When this returns, you can use the FileCount property to get the number of files in the zip, and the FileCompressionMethod, FileCompressionRatio, FileCRC, FileDate, FileDirectory, FileEncrypted, FilePackedSize, and FileSize methods to display information about the files. You can restrict which files are extracted in an Unzip operation using the FileSelected property. By default, this property is set to True for all files, just set it to False for the files you don't want to extract.

Progress and Cancel

As Directory listings and Unzip operations are performed, the class will raise the Progress event, which you can use to display status messages about the directory operation, and Cancel events, which allows you to stop the directory or unzip operation.

Dealing With Password Protected Zips

The PasswordRequest event is raised when you attempt to extract a file from an encrypted ZIP. Here you can supply the password and optionally cancel the extract operation.

Overwrite Prompts

If you set the PromptToOverwrite option, you will also get OverwritePrompt events to respond to whenever the ZIP DLL encounters an existing file. Through this method you can decide whether to overwrite a given file or not and also whether the same response should be applied to all other files in the ZIP.

The remainder of the properties of the class allow you to set unzipping options, such as UseFolderNames, ExtractOnlyNewer and OverwriteExisting.