Skip to main content

UnZip (script step reference)

Troi File Plug-in for FileMaker Pro

UnZip

Expands a ZIP file into the specified folder.

SyntaxScript step badge

UnZip [ Select ; Result (error) ; Zip filePath ; Destination folderPath ;
        Don't create archive folder ; Overwrite Existing items ; Timeout ]

Options

Select entire contents replaces the entire contents of a field with the result. If not checked the result replaces the currently selected portion of the field
Result (error) an error code
Zip filePath the path to the ZIP file to be unzipped
Destination folderPath the path to the folder where the ZIP is going to be expanded
Don’t create archive folder don’t create an extra top folder if there are multiple items at the top level of the ZIP file
Overwrite Existing items overwrite existing items in the destination folder(s)
Timeout specify the timeout time in seconds (default = 20 seconds)

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 unzipped
$$-43 fnfErr source file not found
$$-48 dupFNErr destination ZIP folder already exists

Other errors may be returned.

Originated in

Troi File Plug-in 9.0

Compatibility

FileMaker Pro 16 to FileMaker Pro 2023

Considerations

The UnZip step will create the complete (sub)folder structure of the ZIP. This may take a bit of time for large ZIP files.

WARNING only use the option “Overwrite Existing items” when you are sure you don’t overwrite something important. If you first want to see what is in the ZIP file you can use the TrFile_GetZipInfo function to get a list of items. Alternatively it might be better to extract the contents of the ZIP in an empty folder first, and then copy the extracted files from that folder.

Example

UnZip [ Select ; $ErrorCode ; "D:\myZIP2016.zip" ; "C:\resultDir\" ]

This will uncompress the ZIP file myZIP2016.zip into the folder resultDir. For example these files and folders might be created on the disk:

C:\resultDir\my report\illustration.jpg
C:\resultDir\my report\my report\extra data\
C:\resultDir\my report\my report\extra data\note.txt

Example 2

We assume that in your FileMaker file the following fields are defined and filled with the paths to the source ZIP file and destination folder:

   this::sourceZipPath      	may contain something like "MacHD:Users:kip:bigtext.zip" 
   this::destOfUnZIP_Path	may contain something like "MacHD:Users:destFolder"

This example will first set the variables from the paths stored in the two fields, and then expand the ZIP file. In a script add the following steps:

# Initialize: copy the fields into variables first:
Set Variable [ $SourceZIPfilePath ; this::sourceZipPath ]
Set Variable [ $DestinationFolder ; this::destOfUnZIP_Path ]

# Now unZIP it:
UnZip  [ Select ; $ErrorCode ; $SourceZIPfilePath ; $DestinationFolder ; 
	Overwrite Existing items ]

# Return the resulting error code:
Exit Script [ $ErrorCode ]

NOTE: in this example we have specified the option “Overwrite Existing items” . Only use this option if you want to allow that existing items in the destination folder can be overwritten.

Related script stepScript step badge

Create Zip

Related functionsFunction badge

TrFile_GetZipInfo
TrFile_UnZip

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 16 to 2023 –> UnZip (filep7304) 2023-0601 16:38:49