Create a ZIP file, from the specified file or folder.
TrFile_CreateZip ( switches ; sourcePath ; destZipFile )
|switches||this alters the behavior of the function|
|sourcePath||the path to the source file or folder to be zipped|
|destZipFile||the path to the new ZIP file to be created|
Switches can be empty or this:
|-TimeoutSecs=x||specify the timeout time in x seconds (default = 20 seconds)|
|-DontAddEnclosingFolder||the top folder will not be added to the ZIP file, only the contents of the top folder.|
Data type returned
The returned result is an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:
|0||no error||The ZIP file was created|
|$$-43||fnfErr||Source file not found|
|$$-48||dupFNErr||Destination ZIP file already exists|
Other errors may be returned.
Troi File Plug-in 8.0
FileMaker Pro 15 to 19
You can zip a single file or a complete folder, including subfolders and all items contained in the folder.
Zipping many items can take a long time. With the “-TimeoutSecs=x” switch you can increase the timeout time so it is long enough.
v12.0 added the switch “-DontAddEnclosingFolder”
Set Field [ $ErrorCode ; TrFile_CreateZip ( "-Unused" ; "C:\dataDir\" ; "D:\myZIP2015.zip" ) ]
This will create a compressed ZIP file archive myZIP2015.zip with the contents of the folder dataDir.
We assume that in your FileMaker file the following fields are defined and filled with the paths to the source and destination ZIP file:
this::sourcePath may contain something like "MacHD:Users:kip:bigtext.doc" this::destinationZIPPath may contain something like "MacHD:Users:kip:bigtext.zip"
This example will first set the variables from the paths stored in the two fields, and then create the ZIP file:
In a script add the following steps:
# Initialize: copy the fields into variables first: Set Variable [ $SourcePath ; this::sourcePath ] Set Variable [ $DestinationZIP ; this::destinationZIPPath ] # # Now zip it: Set Variable [ $ErrorCode ; TrFile_CreateZip ( "-Unused" ; $SourcePath ; $DestinationZIP ) ]