Click here to Skip to main content
11,720,324 members (81,128 online)
Click here to Skip to main content

SAWZip - zip file manipulation control

, 29 Aug 2001 299.8K 4.8K 59
Rate this:
Please Sign up or sign in to vote.
An ATL based control for reading and writing zip files.


While I was developing my Java Class Browser (JCB) I needed a control or sourcecode (C++) to read jar-files. I searched the web and I didn't find any good freeware to resolve this problem. What I found was the zlib-compression library of Jean-loup Gailly and Mark Adler. It was not easy to figure it out how it worked. After a while I found the library written by Tadeusz Dracz. He uses the zlib-compression in a MFC library. It gave me a good idea on how to use the zlib-compression library. The problem with his library was that it was written with MFC, and I want to avoid using MFC because I JCB is a WTL-program. That's why I started to develop an ATL-control based on the code I found in the sourcecode of Tadeusz Dracz.

You can use this control with Visual C++ and Visual Basic 6.0. The control has been tested on Windows 98 and Windows NT. The UNICODE version of the application is not yet tested on a Windows NT Platform.

Archive Object


Property Type R/W Description
Name String R The name of the zipfile.
Files Files Object R A collection of file-objects.
Comment String R/W The comment for the zipfile.
ReadOnly Boolean R True when the zip you opened is read-only. Test on this flag before you want to compress some files.


Name Returns Parameters Description
Close / / Closes the zipfile.
Create / ByVal aName as String The name of the zipfile to create
Open / ByVal aName as String The name of the zipfile to open

Files Object


Property Type R/W Description
Count long R Number of files in the archive.


Name Returns Parameters Description
Add / ByVal newVal as File Adds a file to the archive. When there's already a file compressed with the same name it will be override this file.
AddFileByName / ByVal aName as String,
ByVal level as Integer,
ByVal fullPath as Boolean,
ByVal refresh as Boolean
This method can add files with wildcards. For level and fullPath see File Object for more information. When refresh is set to true, the file with the same name in the archive is overwritten. When it is set to false, the file will be skipped.

The following example does the following: Adding all C++ sources in the current-directory to the archive. Overwrite the current files in the archive.
zip.Files.AddFileByName "*.cpp", 1, true, true
Item File ByVal index as Long Returns the file on position index.
Remove / ByVal index as Long Removes the file with position index from the archive.

File Object


Property Type R/W Description
Name String R/W The name of the file. When added with fullPath set to false, the path will not be stored in the archive.
Directory Boolean R Returns true when the file is a directory.
CompressedSize Long R The size of the file when compressed.
UncompressedSize Long R The size of the file when not compressed.
Level Integer R/W The level used to perform compression. A value in the range of 0 - 9. 0 is no compression at all. 1 gives best speed, 9 gives best compression. This can only be set when the file is not yet stored in the archive.
Crc32 Long R Returns the crc checkum value.
Comment String R/W Returns or sets the comment. The comment can only be set when the file is not yet in stored in the archive.
FullPath Boolean R/W When stored to the archive and FullPath is false the path-information will be discarded. When the file is extracted and the FullPath is false the file will be extracted without the path-information.
Index Long R The index of this file object in the Files collection. This will be -1 when the file is not yet stored in the archive.


Name Returns Parameters Description
Extract / ByVal aPath as String Extract the file into the specified path. When FullPath is set to false, the file will be stored without the path-information.


This control uses the dll-version of the zlib-compression library. When you install this control the zlib.dll must be reachable. This control makes heavy use of private interfaces to communicate between the different objects. You can read more about this on my page of SAWEditListCtrl on how to accomplish this.


Here is a list of resources I used to develop this control:

The MFC Library of Tadeusz Dracz.
The zlib-compression home page.


27-Dec-2000    Version 1.0 Released.

8-Mar-2001    Version 1.1

  1. Add properties to the fileobject to retrieve the dates of the files
  2. Extracting to a stringbuffer

18-Apr-2001    Version 1.2

  1. Solved a bug in AddFileByName.

23-May-2001    Version 1.4

  • Added a new property for testing on readonly zip-files. Now you can extract from a file from readonly-files.
  • Resolved a memory-leak after extracting a file. (Thanks go to Brad Gutilla).

28-Jun-2001    Version 1.6

  • Version 1.6: Bug resolved in the extract-method. When fullpath was true and the directory didn't exist a Can't create file occured. Now the fullpath is created before extracting. (Thanks Nat Dickinson)

30-Aug-2001 Version 2.0

  • Version 2.0: Solved the comment-bug on the archive-object. Compatible for Win95-users. (Thanks to Frederic St-Laurent)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Franky Braem
Web Developer
Belgium Belgium
Programmer since 1991 using C/C++/Visual Basic and Java. Playing with wxWindows at home.

You may also be interested in...

Comments and Discussions

GeneralSelf Extracting Pin
bibilm16-May-02 5:22
memberbibilm16-May-02 5:22 
GeneralErrorr in windows 2000 Pin
randheer10-Jan-02 1:29
memberrandheer10-Jan-02 1:29 
GeneralException when Extracting Files Pin
Thilo Krause2-Jan-02 6:00
memberThilo Krause2-Jan-02 6:00 
GeneralRe: Exception when Extracting Files Pin
Hzi24-Jan-02 22:36
memberHzi24-Jan-02 22:36 
GeneralBug: Handle being left opened Pin
Paul Wolfensberger28-Nov-01 4:19
memberPaul Wolfensberger28-Nov-01 4:19 
GeneralError in opening a file from VC++ Pin
Puneet31-Aug-01 12:15
memberPuneet31-Aug-01 12:15 
GeneralError regsvr32.exe and SAWZIP.dll Pin
Anonymous20-Aug-01 3:43
memberAnonymous20-Aug-01 3:43 
GeneralRe: Error regsvr32.exe and SAWZIP.dll Pin
F Braem20-Aug-01 4:00
memberF Braem20-Aug-01 4:00 
GeneralRe: Error regsvr32.exe and SAWZIP.dll Pin
J.P.20-Aug-01 4:56
memberJ.P.20-Aug-01 4:56 
GeneralRe: Error regsvr32.exe and SAWZIP.dll Pin
Bogdan Zamfir21-Nov-01 11:12
memberBogdan Zamfir21-Nov-01 11:12 
GeneralRe: Error regsvr32.exe and SAWZIP.dll Pin
Wolwer29-Apr-02 21:49
memberWolwer29-Apr-02 21:49 
GeneralRe: Error regsvr32.exe and SAWZIP.dll Pin
DeveloperDude3-Jun-04 13:36
memberDeveloperDude3-Jun-04 13:36 
GeneralRe: Error regsvr32.exe and SAWZIP.dll Pin
wstein19-Aug-04 10:51
memberwstein19-Aug-04 10:51 
General"Unable to create the file" Pin
Anonymous16-Aug-01 8:28
memberAnonymous16-Aug-01 8:28 
GeneralRe: "Unable to create the file" Pin
Ciborowski Paweł13-Apr-02 2:25
memberCiborowski Paweł13-Apr-02 2:25 
QuestionWhy this message ? Pin
Mauricio Cunha13-Aug-01 6:54
memberMauricio Cunha13-Aug-01 6:54 
AnswerCorrect question Pin
Mauricio Cunha13-Aug-01 6:56
memberMauricio Cunha13-Aug-01 6:56 
GeneralRe: Correct question Pin
Franky Braem13-Aug-01 22:02
memberFranky Braem13-Aug-01 22:02 
GeneralTrouble with the FileSystemObject Pin
Stewart Downey8-Aug-01 8:31
memberStewart Downey8-Aug-01 8:31 
GeneralIn case anyone has trouble with the CRC32... Pin
Anonymous23-Jul-01 21:49
memberAnonymous23-Jul-01 21:49 
GeneralExceptions throw by SAWZip Pin
improvwheels1-Jul-01 19:07
memberimprovwheels1-Jul-01 19:07 
GeneralRe: Exceptions throw by SAWZip Pin
Franky Braem1-Jul-01 20:50
memberFranky Braem1-Jul-01 20:50 
GeneralRe: Exceptions throw by SAWZip Pin
improvwheels1-Jul-01 21:39
memberimprovwheels1-Jul-01 21:39 
GeneralRe: Exceptions throw by SAWZip Pin
Franky Braem2-Jul-01 1:40
memberFranky Braem2-Jul-01 1:40 
GeneralRe: Exceptions throw by SAWZip Pin
VincentMes26-Oct-01 4:28
memberVincentMes26-Oct-01 4:28 
Generalzlib.h missing Pin
Moin Anjum28-May-01 1:05
memberMoin Anjum28-May-01 1:05 
GeneralRe: zlib.h missing Pin
F Braem28-May-01 2:55
memberF Braem28-May-01 2:55 
GeneralRe: zlib.h missing Pin
Moin Anjum28-May-01 3:22
memberMoin Anjum28-May-01 3:22 
GeneralCompile error Pin
Anonymous26-May-01 0:07
memberAnonymous26-May-01 0:07 
GeneralRe: Compile error Pin
F Braem28-May-01 2:49
memberF Braem28-May-01 2:49 
GeneralRegister Failed Pin
Anonymous28-May-01 16:57
memberAnonymous28-May-01 16:57 
GeneralRe: Register Failed Pin
Franky Braem6-Jun-01 21:16
memberFranky Braem6-Jun-01 21:16 
GeneralThanks a lot!! Pin
Anonymous11-Jun-01 20:02
memberAnonymous11-Jun-01 20:02 
GeneralMemory Leak Pin
Anonymous9-May-01 14:24
memberAnonymous9-May-01 14:24 
GeneralFile name inside de zip archive Pin
Antxon Alonso24-Apr-01 23:19
memberAntxon Alonso24-Apr-01 23:19 
GeneralRe: File name inside de zip archive Pin
Franky Braem25-Apr-01 1:39
memberFranky Braem25-Apr-01 1:39 
GeneralRe: File name inside de zip archive Pin
Anonymous15-Jun-01 3:16
memberAnonymous15-Jun-01 3:16 
GeneralUse version 1.5 Pin
Franky Braem19-Jun-01 23:38
memberFranky Braem19-Jun-01 23:38 
GeneralError in VB Demo Pin
Anonymous21-Mar-01 9:27
memberAnonymous21-Mar-01 9:27 
GeneralRe: Error in VB Demo Pin
Franky Braem23-Mar-01 2:31
memberFranky Braem23-Mar-01 2:31 
QuestionWhere are the Files ??? Pin
Goran Lastro8-Mar-01 23:10
memberGoran Lastro8-Mar-01 23:10 
AnswerRe: Where are the Files ??? Pin
Anonymous10-Mar-01 8:23
memberAnonymous10-Mar-01 8:23 
Questionzlib.dll ?? Pin
cheefarr1-Feb-01 20:39
membercheefarr1-Feb-01 20:39 
AnswerRe: zlib.dll ?? Pin
Franky Braem1-Feb-01 23:34
memberFranky Braem1-Feb-01 23:34 
GeneralBroken DL Links Pin
Anonymous24-Jan-01 14:28
memberAnonymous24-Jan-01 14:28 
GeneralRe: Broken DL Links Pin
Anonymous24-Jan-01 14:57
memberAnonymous24-Jan-01 14:57 
GeneralNice Job Pin
Anatoly Ivasyuk4-Jan-01 9:44
memberAnatoly Ivasyuk4-Jan-01 9:44 
Generaloki Pin
Anonymous3-Jan-01 4:52
memberAnonymous3-Jan-01 4:52 
GeneralRe: oki Pin
Anonymous3-Jan-01 4:59
memberAnonymous3-Jan-01 4:59 
GeneralRe: oki Pin
Anonymous3-Jan-01 5:55
memberAnonymous3-Jan-01 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 30 Aug 2001
Article Copyright 2001 by Franky Braem
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid