ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Archive functions
  • Use condition
  • Compression level
  • Error codes
  • Adding a file that already exists in the archive
  • Index of files in the archive
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Automatically adds and compresses a list of files into a ZIP, CAB, WDZ, 7z, TAR, gzip or TGZ (TAR.GZ) archive. This function is faster than <zipArchive variable>.AddFile run for each file.
New in version 2025
WINDEVWEBDEV - Server codeWindowsLinuxiPhone/iPad gzip (.gz extension) is now supported.
Example
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)Ajax
// Create an archive and add an element 
// With progress bar displayed in a Progress Bar control
MyArchive is zipArchive
NumZipErr is int

NumZipErr = MyArchive.Create("C:\Doc\Archive\ArchiveFile.zip")
IF NumZipErr = 0 THEN
	NumZipErr = MyArchive.AddFileList("C:\doc\Image\House.BMP" + CR +  ...
			"C:\My Projects\WDStock\WDStock.wdp", zipDrive, PROGBAR_Progress)
	IF NumZipErr <> 0 THEN
		Error(zipMsgError(NumZipErr))
	END
	MyArchive.Close()
ELSE
	Error(zipMsgError(NumZipErr))
END
Syntax

Adding a list of files separated by carriage returns (CR) Hide the details

<Result> = <Archive>.AddFileList(<Path of files to add> [, <Path section to store> [, <Progress>]])
<Result>: Integer
  • 0 if the file list has been added,
  • An error code (value greater than 0) otherwise. For more details on these error codes, see the Remarks.
<Archive>: zipArchive variable
Name of the zipArchive variable corresponding to the archive to which the files will be added.
<Path of files to add>: Character string
Name and path of files to be added to the archive, separated by carriage returns (CR). These paths can be full paths or paths relative to the current directory. The length of each path must not exceed 260 characters.
The size of each file must not exceed 4 GB. Otherwise, an error occurs.
You cannot use wildcard characters.
WINDEVReports and QueriesUser code (UMC) This parameter has the following format:
<File path> [ + TAB + <Path to store> ] + RC
If a path is specified, adding the file will be equivalent to calling <zipArchive variable>.AddFile followed by <zipArchive variable>.ChangePath.
<Path section to store>: Optional constant
Indicates the file path section to be stored in the archive. This parameter is only taken into account for files for which <Path to store> was not specified.
zipDirectoryStores the different directories that are part of the path, as well as the file name and extension. For example: \Directory\Files\FileName.pdf
zipDrive
(Default value)
Stores the full and absolute path of the file (disk, directories, file name and extension). For example: C:\Directory\Files\FileName.pdf
ZIP format: This constant has no effect.
7z format: This constant and zipDirectory will have the same effect.
LinuxiPhone/iPadIOS WidgetMac Catalyst This constant is not available as there is no drive root.
AndroidAndroid Widget This constant will have the same effect as zipDirectory.
zipNoneStores the file name and extension. For example: FileName.pdf

If you are using an archive in .CAB format, only the zipNone constant is taken into account. The .CAB format does not allow you to store paths in the archive file.
<Progress>: Control name or procedure name
Progress bar management mode. This parameter can correspond to:
If you use a TAR, gzip or TGZ (TAR.GZ) archive, the progress bar is refreshed only after each file is added.
WEBDEV - Server code This procedure must be executed on the server side.

Adding a list of files contained in an array Hide the details

<Result> = <Archive>.AddFileList(<List of files> [, <Progress>])
<Result>: Integer
  • 0 if the file list has been added,
  • An error code (value greater than 0) otherwise. For more details on these error codes, see the Remarks.
<Archive>: zipArchive variable
Name of the zipArchive variable corresponding to the archive to which the files will be added.
<List of files>: Array of zipArchivedFile variables
Array of zipArchivedFile variables used to identify the characteristics of the files to be added.
<Progress>: Control name or procedure name
Progress bar management mode. This parameter can correspond to:
If you use a TAR, gzip or TGZ (TAR.GZ) archive, the progress bar is refreshed only after each file is added.
WEBDEV - Server code This procedure must be executed on the server side.
Remarks

Use condition

You can add files to an archive if:
  • The archive exists (archives are created using <zipArchive variable>.Create).
  • The archive is accessible in read/write mode.
  • The archive is a single-part archive.
  • The size of the file is less than 4 GB.
Caution:
  • The full path of each file is stored in the archives in ZIP or WDZ format.
  • CAB archives: Files must be added immediately after the archive is created. This format does not allow adding files to an existing archive.
  • RAR archives: This function is not available.
  • 7z archives: The archive is fully compressed each time <zipArchive variable>.AddFileList is called.
Maximum number of files allowed:
  • in a WDZ file: 232-1.
  • in a ZIP file: 65535.
  • in a CAB file: 65535.
Reminder:
  • LinuxiPhone/iPadIOS WidgetMac Catalyst Only ZIP, TAR, gzip and TGZ (TAR.GZ) archives are available.
  • AndroidAndroid Widget The CAB format is not available.

Compression level

The files added into a zip archive are compressed by default. You can change the compression level of files added to an archive using function zipCompressionLevel.

Error codes

The following error codes are returned:
  • 1: The path passed as parameter does not exist.
  • 2: Access denied: The user does not have sufficient rights or the file is in use.. If the file to insert is an HFSQL data file, it must be closed by the following code:
    HClose(<File name>)
    Multitask(<Timeout>) // Waits until the file is closed
  • 3: The archive is corrupted.
  • 4: The path does not exist in the archive.
  • 5: Unable to write to the archive.
  • 7: The file already exists in the archive.
  • 8: An archive cannot be added to itself. For example, "MyArchive" cannot be added to "MyArchive".
The message corresponding to the error code is returned by zipMsgError.

Adding a file that already exists in the archive

Adding a file already present in an archive causes an error. A file is identified by its stored path. Therefore, two files with the same name and with the same relative path cannot be added into an archive.

Index of files in the archive

When a file is added to an archive, an index is automatically assigned to that file. This index corresponds to the order in which the files are added to the archive. To select a file in the archive, you can use:
Component: wd300zip.dll
Minimum version required
  • Version 24
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/05/2025

Send a report | Local help