FileReplace

Deletes the file and writes text to the file after creating it.

OutputVar := FileReplace(Text, Filename , Options)
Command  Example: FileReplace "text",A_ScriptDir "\MyFile.txt"
Function Example: Success := FileReplace("text",A_ScriptDir "\MyFile.txt")

Parameters

OutputVar

The name of the variable in which to store true if file was replaced or false otherwise.

Text

The text to append to the file. See more info in FileAppend.

Filename

The name of the file to be appended, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.

Options (optional)

See FileAppend options.

Remarks

FileOpen in append mode provides more control than FileAppend and allows the file to be kept open rather than opening and closing it each time. Once a file is opened in append mode, use file.Write(string) to append the string. File objects also support binary I/O via RawWrite/RawRead or WriteNum/ReadNum, whereas FileAppend supports only text.

Example

FileReplace "New content`n", "C:\My Documents\Test.txt"