Chilkat Examples

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

PowerShell 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

 

 

 

(PowerShell) Add Multiple Files to a ZIP Using AppendFiles

See more Zip Examples

This example demonstrates how to use the AppendFiles method to add multiple files matching wildcard patterns to a ZIP archive.

The example adds:

  • All .txt files from one directory.
  • All .xml files recursively from another directory tree.

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

When recursive mode is enabled (recurse = $true), relative subdirectory paths are preserved within the ZIP archive.

For example, suppose the local filesystem contains the following directory tree:

c:/data/invoices/2024/january/inv001.xml
c:/data/invoices/2024/january/inv002.xml
c:/data/invoices/2024/february/inv003.xml

And the following call is made:

zip.AppendFiles("c:/data/*.xml",$true);

Then the following paths will be stored in the ZIP archive:

invoices/2024/january/inv001.xml
invoices/2024/january/inv002.xml
invoices/2024/february/inv003.xml

The portion of the path preceding the wildcard root (c:/data/) is not stored in the ZIP archive.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$zip = New-Object Chilkat.Zip

$success = $zip.NewZip("appendFilesExample.zip")
if ($success -eq $false) {
    $($zip.LastErrorText)
    exit
}

# Add all .txt files from c:/reports.
# Subdirectories are not included because recurse=ckfalse.
$success = $zip.AppendFiles("c:/reports/*.txt",$false)
if ($success -eq $false) {
    $($zip.LastErrorText)
    exit
}

# Add all .xml files recursively from c:/data.
# Relative subdirectory paths are preserved within the ZIP archive.
$success = $zip.AppendFiles("c:/data/*.xml",$true)
if ($success -eq $false) {
    $($zip.LastErrorText)
    exit
}

# Write the ZIP archive to disk and close it.
# The source files are consumed at this time.
$success = $zip.WriteZipAndClose()
if ($success -eq $false) {
    $($zip.LastErrorText)
    exit
}

$("ZIP archive created successfully.")

 

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