By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt FileWrite Function

Reference on the AutoIt FileWrite Function. Including useful example.

Edited: 2015-02-13 00:10

The AutoIt FileWrite function is used to write data to a file that has previously been opened in write mode.

The function will use the ANSI format – to use another format, you will need to open the file using FileOpen with the relevant flags.

The Function either accepts the filename of the file to be opened, or the file handle of a file that has previously been opened using the FileOpen function. If using filenames, the file will automatically be opened and closed, and even created if it does not already exist.

Returns 1 on success, and 0 if the file is not opened in write mode, is read-only, or otherwise fails.

AutoIt FileWrite Example

The below is a short example demonstrating how to first open a file, write a couple of lines to it, and then finally close it using FileClose.

See also: Autoit FileWrite Tutorial

$file = FileOpen("SomeFile.txt", 1)

FileWrite($file, "First line of the file." & @CRLF) ; The CRLF at the end is a line break
FileWrite($file, "Second line of the file.")