Skip to main content

TrFile_CreateZip (function reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
Troi File Plug-in for FileMaker Pro

TrFile_CreateZip

Create a ZIP file, from the specified file or folder.

SyntaxFunction badge

TrFile_CreateZip ( switches ; sourcePath ; destZipFile )

Parameters

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

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.
-DontAddDS_Store don’t add hidden .DS_Store files to the ZIP file
-AddMacOSXAttributes also add extended attributes and resource forks to the ZIP file

On Windows you can also add the switch:

-ForceUTF8Filenames” all filenames in the ZIP file will be UTF-8 encoded. On macOS this is default and the switch has no effect.

Returned Result

Data type returned

Error code

Result

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.

Originated in

Troi File Plug-in 8.0

Compatibility

FileMaker Pro 17 to FileMaker Pro 21 (2024)

Considerations

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.

When you add the switch “-AddMacOSXAttributes” any extended attributes and resource forks are added to the ZIP file in a separate “__MACOSX” folder at the top level.

v12.0 added the switch “-DontAddEnclosingFolder”
v12.1 added the switch “-DontAddDS_Store” and “-AddMacOSXAttributes”
v13.0 added the switch “-ForceUTF8Filenames”

Example

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.

Example 2

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 ) ]

Used in example file

ZIPAndUnZIP.fmp12

Related functionsFunction badge

TrFile_CopyFile
TrFile_CreateFile
TrFile_GetZipInfo
TrFile_UnZip

Related script stepScript step badge

Create Zip

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_CreateZip (filep4303) 2024-0604 19:27:27