Zip (compress files)
ts
function Zip(what, zipArchive, password, method: string): boolean;The Zip function creates a compressed (zip) archive with the files that are passed to it in the what argument (supports wildcards). If the destination zip archive already exists it will be overwritten and replaced.
This function accepts the following parameters:
| Parameter | Type | Requirement | Explanation |
|---|---|---|---|
what | string | required | must be a valid and existing path or a wildcard path |
zipArchive | string | required | fully qualified path to the zip archive to be created |
password | string | optional | if this is not empty the zip archive will be encrypted |
method | string | optional | compression algorithm to use; one of "deflate" (default), "bzip2", "zstd", "xz", "store". Ignored when password is set, encrypted archives always use deflate. Do not pass this parameter together with a password. |
Possible return values:
| Value | Explanation |
|---|---|
true | the function succeeded: the zip archive was created |
false | the function failed: the zip archive was not created |
Example
ts
{
// Basic usage — deflate compression (default)
Zip('./documents/*.docx', './archives/dox.zip');
// Encrypted archive — method is always deflate, do not pass a 4th argument
Zip('./documents/*.docx', './archives/dox.zip', 's3cr3t');
// Explicit compression method — no password
Zip('./documents/*.docx', './archives/dox.zip', '', 'zstd');
}