Chilkat Examples

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

Unicode C++ 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
Apple Keychain
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

 

 

 

(Unicode C++) Unzip an Entire ZIP Archive While Preserving Directory Structure

See more Zip Examples
Extract an Entire ZIP Archive While Preserving Directory Structure

This example demonstrates how to use the Unzip method to extract all files and directories from a ZIP archive.

The example shows how the stored ZIP directory structure is recreated beneath the target extraction directory.

Suppose the ZIP archive contains:

aaa/pigs.json
bbb/base64Cert.txt
bbb/sub1/brasil_cert.pem
bbb/sub2/penguins.gif
bbb/sub2/starfish.jpg
hamlet.xml
hello.pdf

After extraction to:

c:/temp/testDir

The following filesystem structure will be created:

c:/temp/testDir/aaa/pigs.json
c:/temp/testDir/bbb/base64Cert.txt
c:/temp/testDir/bbb/sub1/brasil_cert.pem
c:/temp/testDir/bbb/sub2/penguins.gif
c:/temp/testDir/bbb/sub2/starfish.jpg
c:/temp/testDir/hamlet.xml
c:/temp/testDir/hello.pdf

If the target extraction directory does not already exist, it is automatically created.

The Unzip method returns the number of files extracted, or -1 if the extraction fails.

Chilkat C/C++ Library Downloads

MS Visual C/C++

C++ Builder

Linux C/C++

Alpine Linux C/C++

MacOS C/C++

iOS C/C++

Android C/C++

MinGW C/C++

#include <CkZipW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkZipW zip;

    // Open an existing ZIP archive.
    success = zip.OpenZip(L"qa_data/zips/sample.zip");
    if (success == false) {
        wprintf(L"%s\n",zip.lastErrorText());
        return;
    }

    // ------------------------------------------------------------
    // Extract all files to:
    // 
    //     c:/temp/testDir
    // 
    // If the target directory does not already exist,
    // Chilkat will automatically create it.
    // 
    // The Unzip method recreates the stored ZIP directory
    // structure beneath the target directory.
    // 
    int numFilesUnzipped = zip.Unzip(L"c:/temp/testDir");

    if (numFilesUnzipped < 0) {
        wprintf(L"%s\n",zip.lastErrorText());
        return;
    }

    wprintf(L"Number of files extracted = %d\n",numFilesUnzipped);
    wprintf(L"\n");

    // ------------------------------------------------------------
    // Suppose the ZIP archive contains these entries:
    // 
    //     aaa/pigs.json
    //     bbb/base64Cert.txt
    //     bbb/sub1/brasil_cert.pem
    //     bbb/sub2/penguins.gif
    //     bbb/sub2/starfish.jpg
    //     hamlet.xml
    //     hello.pdf
    // 
    // After extraction, the following files will exist:
    // 
    //     c:/temp/testDir/aaa/pigs.json
    //     c:/temp/testDir/bbb/base64Cert.txt
    //     c:/temp/testDir/bbb/sub1/brasil_cert.pem
    //     c:/temp/testDir/bbb/sub2/penguins.gif
    //     c:/temp/testDir/bbb/sub2/starfish.jpg
    //     c:/temp/testDir/hamlet.xml
    //     c:/temp/testDir/hello.pdf
    // 
    // The ZIP directory structure is preserved during extraction.

    // Close the ZIP archive.
    zip.CloseZip();

    wprintf(L"Unzip completed successfully.\n");
    }

 

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