The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
3 Code Libraries &nbsp
&nbsp

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



NOTE: this code has been superceded by the version at the new site.




Unzip Demonstration Project

Download Code
VB5 codeVB6 code Download the Unzip Sample project (83kb)
VB5 codeVB6 code Download the Info-ZIP Unzip DLL (renamed to vbuzip10.dll prevent clashes with other versions) (64kb)

&nbsp Before you Begin &nbsp
&nbsp This project requires vbuzip10.dll to be placed in your Windows\System directory. vbuzip10.dll is Info-ZIP's unzip32.dll version 5.40, which has been renamed. You can download the original from this link: ftp://ftp.cdrom.com/pub/infozip/WIN32/. Make sure you have visited Info-ZIP's website and read their licensing conditions and requirements before using this DLL. &nbsp
&nbsp This project requires the vbAccelerator Folder Browse Component.. Make sure you have loaded and registered this before trying the project. &nbsp

&nbsp

Overview
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 face 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 DLL 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.





TopBack to top
Source Code - What We're About!Back to Library Source Code
Source Code - What We're About!Back to Source Code

&nbsp

AboutContributeSend FeedbackPrivacy

Copyright 2000, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 21 March 2000