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

Zipping files using the free Info-Zip Zip DLL with VB

Add the ability to ZIP up data to your application without needing third-party controls

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

Zip Demonstration Project

Download Code
VB5 codeVB6 code Download the Zip Sample project (37kb)
VB5 codeVB6 code Download the Info-ZIP Zip DLL (renamed to vbzip10.dll prevent clashes with other versions) (72kb)

&nbsp Before you Begin &nbsp
&nbsp This project requires vbzip10.dll to be placed in your Windows\System directory. vbuzip10.dll is Info-ZIP's zip32.dll version 2.32, which has been renamed. You can download the original from this link: Make sure you have visited Info-ZIP's website and read their licensing conditions and requirements before using this DLL. &nbsp


This article provides a class to enable you to simply add the ability to zipping files in a VB application. With this class you can create zips which recurse subdirectories, store full or relative path names, add and delete files from zips, freshen zips - basically everything you would expect to be able to do from a fully featured zipping application, and all under your programmatic control.

Reusing the VB code - Quick Start
To get the simplest overview of the code, extract these two files from the Zip Sample project:
  • cZip.cls
  • mZip.bas
Add these two files to a new project in VB, and then declare a WithEvents instance of the cZip class:

Private WithEvents m_cZip As cZip

The simplest operation is to add a single file to a new zip file. This is all you need to do:

' Set the zip file:
m_cZip.ZipFile = sFile

' Make sure any previously zipped files are cleared:

' Add the name of the file you want to zip:
m_cZip.AddFileSpec "C:\Stevemac\HTML\ssite\index.html"

' Create the zip!

In More Detail
Adding Files to a Zip
Adding files to the zip is accomplished using the AddFileSpec method. A file specification can either be a fully specified path name (e.g. C:\Stevemac\HTML\ssite\index.html), a wildcard specification (e.g. C:\Stevemac\HTML\ssite\*.htm? ) or a relative path (e.g. index.html). Relative paths are taken relative to the BasePath property of the zip. If you wish to store relative directory names in your zip, then you must specify relative paths as the file spec.

AddFileSpec adds additional file specifications to be used during operations. To clear the buffer, use ClearFileSpecs. To modify existing file specifications, you can use FileSpecCount to return how many specifications have been set up and the property FileSpec to read or write the property.

Progress and Cancel
As Zipping 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.

The most important zip options are RecurseSubDirs and StoreFolderNames. When you set RecurseSubDirs, the zip DLL will check for all files starting at the BasePath property and below for matches against each of the FileSpecs. So, for example, if you add "*.*" as a specification, all files in the BasePath folder and below will be added to the zip. The StoreFolderNames option determines whether the zip will include the folder names as well as the file names. The default operation of this option is to store the full folder name, however, if you're FileSpec items are relative paths at or below the BasePath then the zip will include the relative path name instead. Note that relative folder names can only be stored for deeper folders, so ..\MyFolder will not be represented.

Deleting Files
Deleting files from a Zip is accomplished in exactly the same way as zipping, except you use the Delete method instead of the Zip method.

For a more sophisticated zipping sample, check out the VBP Zip utility.

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


AboutContributeSend FeedbackPrivacy

Copyright 2000, Steve McMahon ( All Rights Reserved.
Last updated: 21 March 2000