TrFile_CreateFile |
Creates a new empty file in the location indicated by the filePath. This function requires no user intervention.
Syntax
TrFile_CreateFile ( switches ; filePath )
Parameters
switches | modifies the action of the function |
filePath | the path to the file to create |
Switches
Switches can be empty or:
-CreateFolders | 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 1.0
Compatibility
FileMaker Pro 17 to FileMaker Pro 21 (2024)
Considerations
TIP: You can now also create and set the contents of the file in one step with the function: TrFile_CreateFileWithContents.
You can use FileMaker styled paths, like “filewin:/C:/MyFiles/test.txt”.
Starting with Troi File Plug-in 12.0 you can omit filemac: or filewin: too! Any path starting with a slash will be parsed as a FileMaker style path (of the platform FileMaker is running).
See also the function TrFile_SaveFileDialog to get a filepath for the file.
Example
Set Field [ gErrorCode ; TrFile_CreateFile ( "-Unused" ; "C:\Testtext.txt" ) ]
This will create the empty file “Testtext.txt” on the C disk.
Set Variable [ $ErrorCode ; TrFile_CreateFile ( "-CreateFolders" ; "/macHD/users/ad/nw/foldB/myfile.log" ) ]
This will create the empty file “myfile.log”. 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
We assume that in your FileMaker file the following fields are defined:
gErrorCode Global, number
gDestFilePath Global, text
gDestFilePath should contain the path to the destination and should not exist, for example “D:\Logs\L2000_01.TXT” (Windows) or “Mac HD:Logs:Log 2000_01” (Mac). In a script add the following scriptstep:
Set Field [ gErrorCode ; TrFile_CreateFile ( "-Unused" ; gDestFilePath ) ]
This will create the file indicated in the gDestFilePath.
Used in example file
CreateFile.fmp12
Related functions
TrFile_AppendToFile |
TrFile_CreateFileWithContents |
TrFile_DeleteFile |
TrFile_ExportToFile |
TrFile_InsertContents |
TrFile_SetContents |
TrFile_SetDefaultCreator |
Related script step
Create File |
Related topics
Troi File Plug-in online help (overview)