TextFile.ReadToString

string TextFile.ReadToString ( 

string Filename )

Example 1

text_contents = TextFile.ReadToString(_SourceFolder .. "\\Information.txt");

Reads the contents of the file "Information.txt" and stores the string in the variable text_contents.

Note: _SourceFolder is a built-in variable that contains the path to the folder where the autorun.exe file is located.

Example 2

-- Read the contents of a text file into a string.
contents = TextFile.ReadToString("C:\\MyFile.txt");

-- Check the error code of the last example.
error = Application.GetLastError();
-- If an error occurred, display the error message.
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    -- Replace every occurrence of the string "Robert" with the string "Adam".
    new_contents = String.Replace(contents, "Robert", "Adam", true);

    -- Write out the modified contents of the text file.
    TextFile.WriteFromString("C:\\MyFile.txt", new_contents, false);

    -- Check the error code of the last example.
    error = Application.GetLastError();
    -- If an error occurred, display the error message.
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    end
end

Reads the contents of the file "MyFile.txt" and stores the string in the variable "contents." Every occurrence of the string "Robert" in "contents" is replaced with the string "Adam" and then written back to the text file "MyFile.txt".

See also:  Related Actions