Reference > Script steps reference > Files script steps > Open Data File
 

Open Data File

Opens a data file for use with other data file script steps.

See also 

Options 

Source file is the path of the data file to open. See Creating file paths.

Target is the field or variable to store the opened data file's file ID. If the variable doesn't exist, this script step creates it (see Using variables).

Compatibility 

 

Product 

Supported 

FileMaker Pro Advanced 

Yes 

FileMaker Go 

Yes 

FileMaker WebDirect 

No 

FileMaker Server 

Yes 

FileMaker Cloud products 

Yes 

FileMaker Data API 

No 

Custom Web Publishing 

Yes 

Runtime solution 

No 

Originated in 

FileMaker Pro 18.0 Advanced

Description 

After the file is opened, you can use the file ID in other script steps such as Get Data File Position, Read from Data File, Set Data File Position, and Write to Data File. Data files remain open until you use the Close Data File script step to close the file or until FileMaker Pro Advanced quits.

Notes 

After a file is opened, the read-write position is 0. See Set Data File Position script step.

If a file is already open, Get(LastError) returns 300 ("File is locked or in use").

Only 25 data files can be open at a time. If this limit is exceeded, Get(LastError) returns 2 ("Memory error").

To get the file IDs of all currently open files, use the Get(OpenDataFileInfo) function.

Example 1 

Opens the data file named data.txt and stores the file ID in a variable.

Open Data File [ "data.txt" ; Target: $fileID ]

Example 2 

Checks whether a file named change.log exists in the Documents folder. If it doesn't, the script creates the file, opens it, and displays the file ID.

Set Variable [ $file ; Value: Get ( DocumentsPath ) & "change.log" ]
Get File Exists [ "$file" ; Target: $fileExists ]
If [ not $fileExists ]
Create Data File [ "$file" ; Create folders: Off ]
End If
Open Data File [ "$file" ; Target: $fileID ]
Show Custom Dialog [ "File ID for " & $file & ": " & $fileID ]
Close Data File [ File ID: $fileID ]

Related topics 

Create Data File script step

Script steps reference (alphabetical list)

Script steps reference (category list)