Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

Zip an Entire Directory Tree

Download Chilkat Zip ActiveX

This VB Example program shows how to do Zip compression in Visual Basic. It Zips an entire directory tree into a Zip archive.

' VB Zip Compression Example Program
' Visual Basic program to Zip all files in a directory tree.
Private Sub Command2_Click()
    
    ' Create a ChilkatZip2 object
    Dim ZipFile As ChilkatZip2
    Set ZipFile = New ChilkatZip2
    ZipFile.UnlockComponent UnlockCode.Text
    ZipFile.NewZip OutputZip.Text
    
    ' Add the directory and all files recursively to the Zip object
    ' At this point, the Zip object simply contains references to
    ' files that will be added and compressed when WriteZip is called.
    ' No compression has taken place, and the Zip file has not yet
    ' been created on disk.  This happens when WriteZip is called.
    success = ZipFile.AppendFiles(SourceDir.Text, 1)
    If (success = 0) Then
        MsgBox ZipFile.LastErrorText
        Exit Sub
    End If
    
    ' See if anything was added.
    If (ZipFile.NumEntries = 0) Then
        ZipStatus.Caption = "Error, no files added to the Zip archive."
        Exit Sub
    End If
    
    ' Compress and write to disk.
    ' This is when the Zip file is actually created.
    success = ZipFile.WriteZip()
    If (success = 0) Then
        MsgBox ZipFile.LastErrorText
        Exit Sub
    End If
    
    ZipStatus.Caption = "Success." + vbCrLf + Str(ZipFile.NumEntries) + " files and directories zipped"
        
    ' Demonstrate how to get the contents of the Zip as XML
    Dim fnum As Integer
    fnum = FreeFile()
    Open "zipDirectory.xml" For Output As #fnum
    Print #fnum, ZipFile.GetDirectoryAsXML()
    Close #fnum
    
    ZipFile.CloseZip
    Set ZipFile = Nothing
    
End Sub

Private Sub Form_Load()
    OutputZip.Text = CurDir$ + "\dirTree.zip"
    
End Sub


 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.