Skip to content
Andrew Lambert edited this page Nov 26, 2022 · 8 revisions

PKZip.WriteZip

Method Signatures

 Protected Function WriteZip(ToArchive() As FolderItem, OutputStream As BinaryStream, RelativeRoot As FolderItem, CompressionLevel As Integer = 6, CompressionMethod As Integer = -1) As Boolean
 Protected Function WriteZip(ToArchive() As FolderItem, OutputFile As FolderItem, RelativeRoot As FolderItem, Overwrite As Boolean = False, CompressionLevel As Integer = 6, CompressionMethod As Integer = -1) As Boolean
 Protected Function WriteZip(ToArchive As FolderItem, OutputStream As BinaryStream, CompressionLevel As Integer = 6, CompressionMethod As Integer = -1) As Boolean
 Protected Function WriteZip(ToArchive As FolderItem, OutputFile As FolderItem, Overwrite As Boolean = False, CompressionLevel As Integer = 6, CompressionMethod As Integer = -1) As Boolean

Parameters

WriteZip(FolderItem(), BinaryStream, FolderItem, Integer, Integer)

Name Type Comment
ToArchive FolderItem array A list of files and folders to be archived.
OutputStream BinaryStream The archive stream.
RelativeRoot FolderItem Optional. The root of the directory structure to recreate in the archive.
CompressionLevel Integer Optional. A number between 1 and 9 controlling how aggressive the compression should be (or 0 for no compression).
CompressionMethod Integer Optional. The type of compression (deflate, bzip2, none, etc.) to use. If not specified then deflate will be used if it is available.

WriteZip(FolderItem(), FolderItem, FolderItem, Boolean, Integer, Integer)

Name Type Comment
ToArchive FolderItem array A list of files and folders to be archived.
OutputFile FolderItem The archive file.
RelativeRoot FolderItem Optional. The root of the directory structure to recreate in the archive.
Overwrite Boolean Optional. If True then the OutputFile is overwritten if it exists.
CompressionLevel Integer Optional. A number between 1 and 9 controlling how aggressive the compression should be (or 0 for no compression).
CompressionMethod Integer Optional. The type of compression (deflate, bzip2, none, etc.) to use. If not specified then deflate will be used if it is available.

WriteZip(FolderItem, BinaryStream, Integer, Integer)

Name Type Comment
ToArchive FolderItem The directory to be recursively archived.
OutputStream BinaryStream The archive stream.
CompressionLevel Integer Optional. A number between 1 and 9 controlling how aggressive the compression should be (or 0 for no compression).
CompressionMethod Integer Optional. The type of compression (deflate, bzip2, none, etc.) to use. If not specified then deflate will be used if it is available.

WriteZip(FolderItem, FolderItem, Boolean, Integer, Integer)

Name Type Comment
ToArchive FolderItem The directory to be recursively archived.
OutputFile FolderItem The archive file.
Overwrite Boolean Optional. If True then the OutputFile is overwritten if it exists.
CompressionLevel Integer Optional. A number between 1 and 9 controlling how aggressive the compression should be (or 0 for no compression).
CompressionMethod Integer Optional. The type of compression (deflate, bzip2, none, etc.) to use. If not specified then deflate will be used if it is available.

Return value

Returns True if the operation was successful.

Remarks

Creates a Zip archive in the OutputFile or OutputStream containing the files specified by ToArchive.

If the ToArchive parameter is a FolderItem representing a directory then that directory is recursively archived.

If the ToArchive parameter is an array of FolderItems then those items are added to the archive. If RelativeRoot is specified then it is used to generate relative paths for items in the ToArchive array; if no relative root is specified then all the items are stored in the root of the archive.

Example

This example creates a new zip archive by recursively compressing a directory structure:

  Dim zipfile As FolderItem = GetSaveFolderItem("", "output.zip") ' the zip file
  Dim target As FolderItem = SelectFolder() '  the target folder
  If Not PKZip.WriteZip(target, zipfile) Then MsgBox("Zip error!")

See also

Entry-level points of interest denoted by "☜"



Clone this wiki locally