TrFile_ExportToFile (function reference)

Troi File Plug-in > Functions reference > TrFile_ExportToFile
Troi File Plug-in for FileMaker Pro

TrFile_ExportToFile

Exports the (binary) contents of a container field or variable to a new file.

SyntaxFunction badge

TrFile_ExportToFile ( switches ; source ; filePath )

Parameters

switchesmodifies the behavior of the function
sourcea container field or variable you want to export the (binary) data of
filePaththe destination path you want to export to

Switches

Switches can be empty or one or more of the following:

-OverwriteExistingoverwrite an existing file without generating an error

Returned Result

Data type returned

Error code

Result

The returned result is an error code. Returned error codes can be:

0no errorthe (binary) file was created
$$-50paramErrparameter error
$$-48dupFNErrdestination file already exists

Originated in

Troi File Plug-in 11.0

Compatibility

FileMaker Pro 14 to 18

Considerations

This function can also be used on FileMaker Server.

Example

Set Variable [ $ErrorCode ; TrFile_ExportToFile ( "-OverwriteExisting" ; 
                                                   gContainer ; "Mac HD:photo.jpg" ) ]

This will create a file photo.jpg with the contents of the container field. Note that this will overwrite an existing file.

Example 2

Say you want to export the contents of a container field of all records of a found set to disk. We assume that in your FileMaker file the following fields are defined:

  gErrorCode	Global, number
  theContainer	Container

In a script add the following script steps:

Set Variable [ $ErrorCode ; 0 ]
Go to Record/Request/Page [ First ]
Loop
    # Build the path:
    Set Variable [ $DestPath; Value: Get ( DocumentsPath ) & theContainer ]
    Set Variable [ $Container ; theContainer ]
    Set Variable [ $ErrorCode ; TrFile_ExportToFile ( "-Unused" ; $Container ; $DestPath ) ]
    Exit Loop If [ Left ( $ErrorCode ; 2 )  = "$$" ) ]
    Go to Record [ Next; Exit after last: On ]
End Loop
Set Field [ gErrorCode ; $ErrorCode ]

Related functionFunction badge

TrFile_CreateFile

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 14 to 18 –> TrFile_ExportToFile (filep4321) 2019-0522 15:10:55