Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaJavaScriptNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual Basic 6.0 Examples
Web API Categories

AI
ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
JavaScript
MHT / HTML Email
MIME
Markdown
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual Basic 6.0) Control Stored ZIP Paths Using AppendFromDir and saveExtraPath

See more Zip Examples

This example demonstrates how the AppendFromDir property and the saveExtraPath argument work together to determine the stored paths of files within a ZIP archive.

The example adds the same local filesystem file three times, but stores it in the ZIP archive using three different paths.

The local filesystem file is:

/temp/a/hamlet.xml

The resulting ZIP archive contains:

hamlet.xml
a/hamlet.xml
temp/a/hamlet.xml

The example demonstrates:

  • How saveExtraPath controls whether path information is stored in the ZIP archive
  • How AppendFromDir establishes the base directory used for relative file paths
  • How the same filesystem file can be stored in a ZIP archive using different relative paths
  • That methods such as AddFile initially add only references to filesystem files, and that the actual file reading and compression occur later when WriteZipAndClose is called

The example also illustrates an important rule: when AppendFromDir is set, the filename passed to AddFile should normally be a relative path rather than a fully qualified absolute path.

Note: This example requires Chilkat v11.0.0 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Dim success As Long
success = 0

success = 0

Dim zip As New ChilkatZip

' Initialize the Zip object and set the output filename.
' The .zip file is not created until WriteZip or WriteZipAndClose is called.
success = zip.NewZip("myZip.zip")
If (success = 0) Then
    Debug.Print zip.LastErrorText
    Exit Sub
End If

' This example adds the same local filesystem file three times,
' each time using a different stored path in the ZIP archive.
' 
' The local file is:
' 
'     /temp/a/hamlet.xml
' 
' The ZIP will contain:
' 
'     hamlet.xml
'     a/hamlet.xml
'     temp/a/hamlet.xml
' 

' ------------------------------------------------------------
' Case 1:
' Add the file using only the filename.
' 
' AddFile adds a reference to the file in the local filesystem.
' The file is not read or compressed at this point.  The referenced
' file is consumed later when WriteZipAndClose is called.
Dim saveExtraPath As Long
saveExtraPath = 0

success = zip.AddFile("/temp/a/hamlet.xml",saveExtraPath)
If (success = 0) Then
    Debug.Print zip.LastErrorText
    Exit Sub
End If

' Because saveExtraPath = 0, only the filename is stored
' in the ZIP archive:
' 
'     hamlet.xml
' 

' ------------------------------------------------------------
' Case 2:
' Store the path "a/hamlet.xml" in the ZIP archive.
' 
' AppendFromDir specifies the base directory for relative file paths.
' The AppendFromDir path itself is not stored in the ZIP.
' 
' Because AppendFromDir is set to "/temp", the relative path
' "a/hamlet.xml" refers to the local filesystem file:
' 
'     /temp/a/hamlet.xml
' 
' Because saveExtraPath = 1, the relative path is stored
' in the ZIP as:
' 
'     a/hamlet.xml
' 
zip.AppendFromDir = "/temp"

saveExtraPath = 1

success = zip.AddFile("a/hamlet.xml",saveExtraPath)
If (success = 0) Then
    Debug.Print zip.LastErrorText
    Exit Sub
End If

' ------------------------------------------------------------
' Case 3:
' Store the path "temp/a/hamlet.xml" in the ZIP archive.
' 
' AppendFromDir is changed to "/" so that the relative path
' "temp/a/hamlet.xml" again refers to the same local filesystem file:
' 
'     /temp/a/hamlet.xml
' 
' Because saveExtraPath = 1, the stored ZIP path is:
' 
'     temp/a/hamlet.xml
' 
zip.AppendFromDir = "/"

saveExtraPath = 1

success = zip.AddFile("temp/a/hamlet.xml",saveExtraPath)
If (success = 0) Then
    Debug.Print zip.LastErrorText
    Exit Sub
End If

' ------------------------------------------------------------
' Write the ZIP archive.
' 
' This is where the referenced file is actually read from disk
' and compressed into the .zip archive.
' 
' The resulting ZIP contains the same file three times,
' each with a different stored path:
' 
'     hamlet.xml
'     a/hamlet.xml
'     temp/a/hamlet.xml
' 
success = zip.WriteZipAndClose()
If (success = 0) Then
    Debug.Print zip.LastErrorText
    Exit Sub
End If

Debug.Print "ZIP archive created successfully."

 

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