Chilkat Examples

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

SQL Server 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
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

 

 

 

(SQL Server) Recursively Add Files to a ZIP Using AppendFilesEx

See more Zip Examples

This example demonstrates how to use the AppendFilesEx method to recursively add files from the local filesystem to a ZIP archive while controlling how directory paths and special filesystem attributes are handled.

The example:

  • Recursively scans a directory tree for files
  • Demonstrates how the saveExtraPath argument affects the paths stored within the ZIP archive
  • Includes hidden files
  • Excludes files having the Windows System attribute
  • Shows how local filesystem paths are transformed into ZIP entry paths

The AppendFilesEx method adds references to files in the local filesystem. The files are not actually read or compressed until a Write* method is called.

This method is cross-platform and works on Windows, macOS, Linux, Android, iOS, and other supported operating systems.

Some arguments are Windows-specific:

  • archiveOnly applies only to the Windows Archive attribute
  • includeSystem applies only to the Windows System attribute

On non-Windows operating systems, these Windows-specific options are simply ignored.

Suppose the local filesystem contains the following directory tree:

c:/project/files/docs/readme.txt
c:/project/files/docs/manual.pdf
c:/project/files/images/logo.png

And suppose the following call is made:

zip.AppendFilesEx("c:/project/files",1,saveExtraPath,0,1,0);

If saveExtraPath = 1, the following paths are stored in the ZIP archive:

project/files/docs/readme.txt
project/files/docs/manual.pdf
project/files/images/logo.png

In this case, the extra leading path information from the filePattern is preserved in the ZIP.

If saveExtraPath = 0, the following paths are stored in the ZIP archive instead:

docs/readme.txt
docs/manual.pdf
images/logo.png

In this case, the leading project/files portion of the path is not stored in the ZIP archive.

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @zip int
    EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @zip, 'NewZip', @success OUT, 'appendFilesEx.zip'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @zip
        RETURN
      END

    -- Recursively include all files beneath c:/project/files.
    DECLARE @recurse int
    SELECT @recurse = 1

    -- 
    -- The saveExtraPath argument controls whether the extra leading path
    -- information from the filePattern is included in the stored ZIP paths.
    -- 
    -- For example, suppose the local filesystem contains:
    -- 
    --     c:/project/files/docs/readme.txt
    --     c:/project/files/docs/manual.pdf
    --     c:/project/files/images/logo.png
    -- 
    -- And suppose AppendFilesEx is called with:
    -- 
    --     "c:/project/files"
    -- 
    -- If saveExtraPath = 1, the ZIP stores:
    -- 
    --     project/files/docs/readme.txt
    --     project/files/docs/manual.pdf
    --     project/files/images/logo.png
    -- 
    -- In this case, the extra path information from the filePattern is preserved.
    -- 
    -- ----------------------------------------------------------------
    -- 
    -- If saveExtraPath = 0, the ZIP stores paths relative to the
    -- directory specified by the filePattern:
    -- 
    --     docs/readme.txt
    --     docs/manual.pdf
    --     images/logo.png
    -- 
    -- In this case, the leading "project/files" path is not stored in the ZIP.

    -- ----------------------------------------------------------------
    -- Preserve extra path information within the ZIP archive.
    DECLARE @saveExtraPath int
    SELECT @saveExtraPath = 1

    -- Do not require the Windows archive attribute.
    DECLARE @archiveOnly int
    SELECT @archiveOnly = 0

    -- Include hidden files.
    DECLARE @includeHidden int
    SELECT @includeHidden = 1

    -- Exclude files having the Windows System attribute.
    DECLARE @includeSystem int
    SELECT @includeSystem = 0

    EXEC sp_OAMethod @zip, 'AppendFilesEx', @success OUT, 'c:/project/files', @recurse, @saveExtraPath, @archiveOnly, @includeHidden, @includeSystem

    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @zip
        RETURN
      END

    -- Write the ZIP archive to disk.
    EXEC sp_OAMethod @zip, 'WriteZipAndClose', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @zip
        RETURN
      END


    PRINT 'ZIP archive created successfully.'

    EXEC @hr = sp_OADestroy @zip


END
GO

 

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