Skip to main content

Substitute In File (script step reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
Troi File Plug-in for FileMaker Pro

Substitute In File

Substitutes every occurrence of a specified set of characters in a (text) file with another set of characters you specify, and writes the revised file. The Substitute function is case sensitive.

SyntaxScript step badge

Substitute In File [ Select ; Result (error); Source filePath ;
                     Destination filePath ; Search string ; Replace string ;
                     Ignore case ; Encoding ]


Select entire contents replaces the entire 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
Source filePath the path to the file which is the source for the substitution
Destination filePath (optional) the path where the resulting file must be written to
Search string any text expression or field containing text
Replace string any text expression or field containing text
Ignore case substitute even if the case differs
Encoding the desired character encoding like UTF-8

Returned Result

Data type returned

Error code


The returned result is an error code. An error always starts with two dollars, followed by the error code. You should always check for errors. Returned error codes can be:

0 no error The destination file with the substitutions was created
$$-43 fnfErr Source file not found, or destination directory does not exist
$$-48 dupFNErr Destination file already exists
$$-1 genericErr The substitution could not be made

Other errors may be returned.

Originated in

Troi File Plug-in 9.0


FileMaker Pro 17 to FileMaker Pro 21 (2024)


If the destination parameter is empty the substitution result will be saved in the source file itself. This happens also when you specify the same source file and destination file. Note that the plug-in uses a temporary file to implement this feature, which can require the same amount of disk space as the source file. The plug-in can fail if there is not enough space on the disk.

NOTE The length of the search and replace string can be up to 1 GB.


Substitute In File [ Select ; $ErrorCode ; "C:\Data\" ; "C:\" ; 
		"country" ; "world" ; Ignore case ]

This will create the file “C:\Main.TAB” where all occurrences of “country” are replaced with the string “world”. The case is ignored, so that also a string “Country” will be substituted.

Example 2

We assume that in your FileMaker file the following fields are defined:

    gErrorCode		Global, number			
    gSourceFilePath	Global, text			
    gDestFilePath 	Global, text
    gSearchStr		Global, text
    gReplaceStr		Global, text

gSourceFilePath should contain the path to an existing file, for example “D:\TempLogs\Log01.TXT” (Windows) or “Mac HD:TempLogs:Log 1” (Mac).
gDestFilePath should contain the path to the destination and should not exist, for example “D:\Output\L2000_01.TXT” (Windows) or “Mac HD:Output:Log 2000_01” (Mac). In a script add the following scriptstep:

Substitute In File [ Select ; $ErrorCode ; gSourceFilePath ; gDestFilePath ; 
			gSearchStr ; gReplaceStr ) ]

This will create a new file gDestFilePath where all occurrences of gSearchStr are replaced with the contents of gReplaceStr.

Related script stepScript step badge

Insert in File

Related functionFunction badge


Related topics

Troi File Plug-in online help (overview)

Online Help Page for Troi File Plug-in for 17 to 2024 –> Substitute In File (filep7283) 2024-0604 19:18:30