This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
ZIP Create archive
|
ZIP Create archive ( fileOrFolder | zipStructure ; destinationFile {; options} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
fileOrFolder | zipStructure | Object |
![]() |
File or Folder object to compress | |||||
destinationFile | Object |
![]() |
Destination file for the archive | |||||
options | Longint |
![]() |
If fileOrFolder used: ZIP Without enclosing folder | |||||
Function result | Object |
![]() |
Status object | |||||
The ZIP Create archive command creates a compressed ZIP archive object and returns the status of the operation.
You can pass either a fileOrFolder or a zipStructure object as first parameter.
Property | Type | Description | ||||||||||||
compression | integer |
| ||||||||||||
encryption | integer | The encryption to use if a password is set:
| ||||||||||||
password | text | A password to use if encryption is required. | ||||||||||||
files | collection |
| ||||||||||||
callback | formula | A callback formula that will receive the compression progress (0 - 100) in $1. |
In the destinationFile parameter, pass a File object describing the ZIP archive to create (name, location, etc.). It is advised to use the ".zip" extension if you want the ZIP archive to be processed automatically by any software.
The optional options parameter allows you to compress only the contents of fileOrFolder (i.e., exclude the enclosing folder): by default, when you pass a Folder in the fileOrFolder parameter, ZIP Create archive will compress the folder and its contents, so that the decompressing operation will recreate a folder. If you want the decompressing operation to compress only the contents of the folder, pass the ZIP Without enclosing folder constant in the options parameter.
Once an archive is created, you can use the ZIP Read archive to access it.
The returned status object contains the following properties:
Property | Type | Description |
statusText | text | Error message (if any):
|
status | longint | Status code |
success | boolean | True if archive created successfully, else false |
To compress a File:
C_OBJECT($file;$destination;$status)
$destination:=Folder(fk desktop folder).file("MyDocs/file.zip")
$file:=Folder(fk desktop folder).file("MyDocs/text.txt")
$status:=ZIP Create archive($file;$destination)
To compress a Folder without the folder itself:
C_OBJECT($folder;$destination;$status)
$destination:=Folder(fk desktop folder).file("MyDocs/Images.zip")
$folder:=Folder(fk desktop folder).folder("MyDocs/Images")
$status:=ZIP Create archive($folder;$destination;ZIP Without enclosing folder)
To compress a ZIP archive structure with a password and progress bar:
C_OBJECT($zip;$status;$destination)
C_LONGINT(progID)
$destination:=Folder(fk desktop folder).file("MyDocs/Archive.zip")
$zip:=New object
$zip.files:=Folder(fk desktop folder).folder("MyDocs/Resources").folders()
$zip.password:="password"
$zip.callback:=Formula(myFormulaCompressingMethod($1))
progID:=Progress New //we use the 4D Progress component
$status:=ZIP Create archive($zip;$destination)
Progress QUIT(progID)
myFormulaCompressingMethod:
C_LONGINT($1)
Progress SET PROGRESS(progID;Num($1/100))
You want to pass a collection of folders and files to compress to the zipStructure object:
C_OBJECT($zip;$destination;$err)
$zip:=New object
$zip.files:=New collection
$zip.files.push(New object("source";Folder(fk desktop folder).file("Tests/text.txt")))
$zip.files.push(New object("source";Folder(fk desktop folder).file("Tests/text2.txt")))
$zip.files.push(New object("source";Folder(fk desktop folder).file("Images/image.png")))
$destination:=Folder(fk desktop folder).file("file.zip")
$err:=ZIP Create archive($zip;$destination)
Product: 4D
Theme: File and Folder
Number:
1640
Created: 4D v18
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)