Zip.Add

Zip.Add ( 

string   ZipFile,

table    Files,

boolean  IncludeFolderNames = true,

string   Password = "",

number   CompFactor = 5,

function CallbackFunction = nil,

boolean  Recurse = false )

Description

Adds files to a Zip archive.

Parameters

ZipFile

(string) The full path and file name of the Zip archive file.

Files

(table) A table containing the full paths to all of the files you want to add. You can also use the * and ? wildcards in this table to add all files from one directory, for example, {"C:\\MyFolder\\*.*"}.

When a wildcard is used, each file will be added relative to the base folder. For example, if the file table references {"C:\\MyFolder\\*.*"} and "MyFolder" contains one file called "One.txt" and a folder called "MyInsideFolder" containing a file "Two.txt", the base folder would be "MyFolder".  If you want to recurse subfolders, the Recurse parameter must be set to true.

IncludeFolderNames

(boolean) Whether to preserve the relative directory structure in the archive when adding files with wildcards.

VALUE

DESCRIPTION

true

Include relative folder names so the structure can be recreated.  (Default)

false

Don't include any relative folder names. (The Zip archive will have no internal directory structure.)

For example, given two files located at:

C:\MyFolder\One.txt
C:\MyFolder\MyInsideFolder\Two.txt

If the file table references {"C:\\MyFolder\\*.*"} and IncludeFolderNames and Recurse is set to true, the Zip archive structure would be:

One.txt
MyInsideFolder\Two.txt

If IncludeFolderNames is set to false, the Zip archive structure would be:

One.txt
Two.txt

Note: If no wildcards are used, no relative folder names will be preserved.

Password

(string) The password to use to protect the Zip file. This password will be needed to extract the files. (This parameter is optional. If you don't want to protect the Zip file, just leave this parameter blank.)

CompFactor

(number) The compression factor to use for the Zip file (0-9). 0 is the fastest and compresses the least, 9 is the slowest and compresses the most. The default is 5.

CallbackFunction

(function) The name of a function that will be called whenever progress is made in adding a file to the Zip archive. (You can use this callback function to display the progress of each file's archiving in your own custom way.)

Note: If CallbackFunction is set to nil, then the progress information will be sent to the built-in status dialog, assuming it is currently visible. (You can show or hide the status dialog with a StatusDlg.Show or StatusDlg.Hide action.)

The callback function must be able to receive the following parameters:

String

(string) The full path and file name currently being added to the Zip archive.

Percent

(number) The progress percentage, corresponding to either the current file or the total action.

Status

(number) The status of the current callback message. Either ZIP_STATUS_MAJOR (value of 0) or ZIP_STATUS_MINOR (value of 1). ZIP_STATUS_MAJOR means that the callback corresponds to the progress of the action as a whole. ZIP_STATUS_MINOR means that the callback corresponds to the progress of the current file.

 

The callback function should return a boolean value (true or false) indicating whether the archiving of the Zip file should continue:

VALUE

DESCRIPTION

true

Continue with the Zip file archiving.

false

Stop the Zip file archiving as soon as possible.

Recurse

(boolean) Whether to recurse subfolders when wildcards are used:

VALUE

DESCRIPTION

true

Recurse subfolders when wildcards are used.

false

Don't recurse subfolders, even if a wildcard is used. (Default)

Returns

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

See also:  Related Actions