Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Zip an Entire Directory Tree
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
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.