Open Data File
Opens a data file for use with other data file script steps.
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 | Yes |
FileMaker Go | Yes |
FileMaker WebDirect | No |
FileMaker Server | Yes |
FileMaker Cloud | Yes |
FileMaker Data API | No |
Custom Web Publishing | Yes |
Originated in version
18.0
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 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.
Copy
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.
Copy
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 ]