Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5    Statistic  


Reads a text file.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
Text 2.4 Yes Yes Yes Yes Yes

MBS( "Text.ReadTextFile"; FilePath { ; Encoding } )

(old name: String.ReadTextFile)


Parameter Description Example value
FilePath The native file path. Something like "/Users/cs/desktop/test.txt" on Mac and "C:\Programs\Data\test.txt" on Windows. Files without path end in the root directory on Mac. "test.txt"
Encoding Optional
The text encoding for result.
Default is native. This function can also handle UTF-16 as well as UTF-16LE and UTF-16BE for little/big endian byte order.
Possible encoding names: ANSI, Arabic-Mac, Arabic-Win, Baltic-Win, CentralEurope-Mac, ChineseSimp-Mac, ChineseSimp-Win, ChineseTrad-Mac, ChineseTrad-Win, Cyrillic-Mac, Cyrillic-Win, EasternEurope-Win, Greek-Mac, Greek-Win, Hebrew-Mac, Hebrew-Win, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-15, Korean-Johab, Korean-Mac, Korean-Win, Latin1, Mac, Native, ShiftJIS-Mac, ShiftJIS-Win, Turkish-Mac, Turkish-Win, UTF-8, DOS or Windows. Pass native to use the native encoding of the current platform.


Returns text on success and error on failure.


Reads a text file.
You have to decide which encoding to use (if not native). We support a few encodings, but we can add more if you need something special. Some characters will be wrong if the encoding is not correct.

See also Files.ReadJPEG, Files.ReadPDF, Files.ReadPNG, Files.ReadFile and RichText.ReadFile.
This function reads only up to 1 GB of text. And even than a 32-bit FileMaker may fail to allocate enough memory to handle the text.

When passing UTF-16 as encoding, we can detect byte order if there is a Byte Order Mark.

This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.


Read system.log file:

MBS("Text.ReadTextFile"; "/var/log/system.log"; "utf8")

Read Windows ANSI XML:

# read and convert to from Windows ANSI to unicode
Set Variable [$text; Value:MBS("Text.ReadTextFile"; "/Users/cs/Desktop/test.xml"; "Windows")]
# remove the encoding hint:
Set Variable [$text; Value:Substitute($text; "<?xml version=\"1.0\" encoding=\"WINDOWS-1252\"?>"; "")]
# now xml is unicode text and can be passed to XML functions.

Read file on Windows from desktop folder:

MBS( "Text.ReadTextFile"; "C:\Users\Christian\Desktop\test.txt")

Read file with UTF-16 Big Endian:

MBS( "Text.ReadTextFile"; "/Users/cs/Desktop/test.txt" ; "UTF-16BE" )

See also

Example Databases

Text.ReadEMLXFile   -   Text.ReadTextFromContainer

Feedback: Report problem or ask question.

MBS Xojo Plugins