Skip to main content

TrFile_ExportToFile (function reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
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

switches modifies the behavior of the function
source a container field or variable you want to export the (binary) data of
filePath the destination path you want to export to

Switches

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

-OverwriteExisting overwrite 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:

0 no error the (binary) file was created
$$-50 paramErr parameter error
$$-48 dupFNErr destination file already exists

Originated in

Troi File Plug-in 11.0

Compatibility

FileMaker Pro 17 to FileMaker Pro 21 (2024)

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 ]

Used in example file

ExportContainer.fmp12

Related functionFunction badge

TrFile_CreateFile

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_ExportToFile (filep4321) 2024-0604 19:37:44