Skip to content

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:

ParameterTypeRequirementExplanation
whatstringrequiredmust be a valid and existing path or a wildcard path
zipArchivestringrequiredfully qualified path to the zip archive to be created
passwordstringoptionalif this is not empty the zip archive will be encrypted
methodstringoptionalcompression 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:

ValueExplanation
truethe function succeeded: the zip archive was created
falsethe 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');
}