Skip to content

ReadTextFile (read a text file)

ts
function ReadTextFile(what: string): string;

Reads the contents of the text file specified by what and returns it as a string. If the file does not exist or an I/O error occurs, the function returns an empty string.

ParameterTypeRequirementExplanation
whatstringrequiredPath to a valid, existing file you wish to read
Return valueExplanation
stringThe entire contents of the file as a single string (may contain unexpected characters if reading a binary file)

Example

ts
var content = ReadTextFile('/home/user/notes.txt');
if (content !== "") {
  Log('File contents: ' + content);
} else {
  Log('File could not be read or is empty.');
}