Create File with Contents |
Creates a new (data) file and fills it with (text) contents in one step.
Syntax
Create File with Contents [ Select ; Result (error) ; FilePath ; Contents ;
Create Folders ]
Options
Select entire contents | replaces the contents of a field with the result. If not checked the result replaces the currently selected portion of the field |
Result (error) | an error code |
FilePath | the path to the file to create |
Contents | the (text) contents |
Create Folders | off/on: also create new folders if they don’t exist in the specified path |
Returned Result
Data type returned
Error code
Result
The returned result is an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:
0 | no error | The file was created |
$$-48 | dupFNErr | Destination file already exists |
$$-1 | genericErr | The file could not be created |
Other errors may be returned.
Originated in
Troi File Plug-in 16.0
Compatibility
FileMaker Pro 17 to FileMaker Pro 21 (2024)
Considerations
This will create the file and directly set the contents of the file in one step.
You can use FileMaker styled paths, like “filewin:/C:/MyFiles/test.txt”.
You can also omit filemac: or filewin:. Any path starting with a slash will be parsed as a FileMaker style path (of the platform FileMaker is running).
See also the script step: Show Save File Dialog to get a filepath for the file.
Example
Create File with Contents [ Select ; gErrorCode ; "C:\Testtext.txt" l "My contents!" ]
This will create the file “Testtext.txt” on the C disk, with as contents the text “My contents!”.
Create File with Contents [ Select ; $ErrorCode ; "/macHD/users/ad/nw/foldB/myfile.txt" ;
"Hello FileMakers!"; Create Folders: on ]
This will create the file “myfile.txt”, with “Hello FileMakers!” as contents. This will also create new folders if they don’t exist in the specified path, for example the folders “nw” and “foldB” may be created.
Example 2
# First find the path to the desktop folder and put it in a variable:
Set Variable [ $DesktopPath ; TrFile_FindFolder( "-Desktop" ) ]
# Now make a (semi) unique filepath:
Set Variable [ $TimeTxt ; Hour(Get(CurrentTime)) & "-" & Minute(Get(CurrentTime)) & "-"
& (Seconds( Get(CurrentTime) ) ]
Set Variable [ $FilePath ; $DesktopPath & "Demo_WithContents" & $TimeTxt & ".txt") ]
Set Variable [ $TheContents ; $TimeTxt & " Success: we created + set the text of the file with Troi File." ]
# Now create and fill the file in one step:
Create File with Contents [ Select ; Result: $ErrorCode ; FilePath: $FilePath ;
Contents: $TheContents " ; Create Folders: off ]
This will create the filled file on the Desktop, and store the error code in the variable $ErrorCode.
Related script steps
Append to File |
Create File |
Delete file |
Insert in File |
Set Contents of File |
Show Save File Dialog |
Related function
TrFile_CreateFileWithContents |
Related topics
Troi File Plug-in online help (overview)