
Command: write
The "write" command is used to write the contents of a string variable to a file. You can perform multiple writes to the same file, appending each write to the existing content, as long as the file remains open. If the file is opened in "wa" mode, the write operation will append the content to the end of the file.
Parameters:
Parameter Name | Type | Description |
---|---|---|
FileID | int | The FileID returned from the "open" function. |
text | string | The text to write, which can span multiple lines. |
Return Value:
The "write" command does not return any value.
Example:
int x = open("myfile.txt");
write(x, "This is the first line\n");
write(x, "This is the second line\n");
close(x);
In this example, we open the file "myfile.txt," write two lines of text to it, and then close the file.
Keeping Files Open Across Several ACF Function Calls
It is possible to maintain a file open for writing across multiple ACF function calls by utilizing a global variable to store the FileID (x in the example above). One function can open the file, write some content to it, and leave it open. Then, another function can continue to write to the same file, and a third function can eventually close it. This approach allows for the coordination of file operations across multiple ACF functions within a FileMaker Script. Alternatively, the function responsible for opening the file can return the FileID back to FileMaker, which can then pass it as a parameter to subsequent ACF functions for write operations and, finally, close the file. This latter method ensures better concurrency control, as separate processes do not share the same FileID, enhancing the reliability of file handling.
References:
- No references