Name
zip.AddFile -- add file to zip archive
Synopsis
idx = zip.AddFile(id, f$[, table])
Function
This function adds the file specified by f$ to the zip archive specified by id and returns the index of the newly added file. The optional table argument allows you to specify further options.

The following tags are currently recognized by the optional table argument:

NewName:
This tag allows you to store this file with a new name in the zip archive. If you want to store the file in a subdirectory in the zip archive, you also have to use this tag and include the name of the subdirectory(s) in NewName. If NewName is omitted, the file will always be stored in the root directory of the zip archive.

Encryption:
This tag allows you to set the desired encryption method for the file. It can be set to one of the following special constants:

#ZIP_EM_NONE:
No encryption. This is the default.

#ZIP_EM_AES_128:
Winzip AES-128 encryption.

#ZIP_EM_AES_192:
Winzip AES-192 encryption.

#ZIP_EM_AES_256:
Winzip AES-256 encryption.

If you specify the Encryption tag, it is also necessary to provide a password that is needed to decrypt the file. You can specify this password in the Password tag (see below). If you don't use the Password tag, the default password set using zip.SetDefaultPassword() is used.

Password:
If the Encryption tag has been set to a value different from #ZIP_EM_NONE (see above), this tag can be set to a password that should be used to protect the file. If you omit this tag, the default password set using zip.SetDefaultPassword() is used.

Compression:
This tag can be used to set the desired compression method for the file. The following compression methods are currently supported:

#ZIP_CM_DEFAULT:
This is the default setting. Currently the same as #ZIP_CM_DEFLATE.

#ZIP_CM_STORE:
Store the file uncompressed.

#ZIP_CM_BZIP2:
Compress the file using the bzip2 algorithm.

#ZIP_CM_DEFLATE:
Deflate the file with the zlib algorithm and default options.

Note that only #ZIP_CM_DEFLATE and #ZIP_CM_STORE can be assumed to be universally supported.

When specifying this tag, you can also pass the CompressionFlags tag to set the compression level (see below).

CompressionFlags:
This tag can be used to define the compression level. It ranges from 1 for the fastest compression and 9 for the highest. You can also pass 0 to use the compressor's default setting. Defaults to 0.

Comment:
This tag can be used to add the file to the zip archive with a comment attached to it.

Time:
This tag can be used to change the file's datestamp. By default, the datestamp will be taken from the file specified in f$. If you'd like to assign a different datestamp to the file, then you need to pass a string in the standard Hollywood date format of dd-mmm-yyyy hh:mm:ss to this tag.

Encoding:
This tag can be used to set the charset encoding that should be used when storing the filename. This can be one of the following special constants:

#ZIP_FL_ENC_UTF_8:
Use UTF-8 encoding. This is the default.

#ZIP_FL_ENC_CP437:
Use code page 437 encoding. Since this was the standard encoding on MS-DOS it was also the standard encoding of the original zip format. So if you need maximum compatibility, you can use this encoding but remember that it can only store Western characters.

(V1.2)

Note that this function doesn't immediately begin compressing the file and writing it to the zip archive. Instead, the file is just added into an internal list and compressing and writing will be done once you call zip.CloseArchive(). This means that you have to make sure that the file you specified in f$ is still available when you call zip.CloseArchive(), i.e. in case you pass the name of a temporary file to f$ you must not delete this temporary file before you call zip.CloseArchive().

Inputs
id
identifier of the zip archive to use
f$
path to a file to add to the zip archive
table
optional: table containing further options (see above)
Results
idx
index of newly added file in zip archive

Show TOC