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

Learn more

AutoIt FileOpen Function

Reference on the FileOpen Function of AutoIt – used to open files for writing or reading.

Edited: 2015-02-13 00:11

The FileOpen Function of AutoIt is used in conjunction with other functions, such as the FileRead or FileWrite functions.

This function opens a file for reading or writing.

The file handle must be closed with the FileClose Function.

Returns -1 on failure, and returns a file handle on success.


Filename and PathThe path and filename for the file to be opened.
Mode OptionalThe mode can be a combination of the following:
  • 0 Read mode (default)
  • 1 Write mode (append to end of file)
  • 2 Write mode (erase previous contents. I.e. Overwrites a file)
  • 8 Creates a directory structure if it doesn't exist.
  • 16 Force binary mode
  • 32 Use Unicode UTF-16 Little-endian. Reading will not override existing byte order mark.
  • 64 Use Unicode UTF-16 Big-endian. Reading will not override existing byte order mark.
  • 128 Use Unicode UTF-8 (with BOM). Reading will not override existing byte order mark.
  • 256 Use Unicode UTF-8 (without BOM).
  • 16384 When opened for reading and no BOM is present, use full file UTF-8 detection.

AutoIt FileOpen Example

In this example a mode value of 10 is used, (2+8) – erases previous content and creates directory.

$file = FileOpen("test.txt", 10)

FileWrite($file, "Line1")
FileWrite($file, "Still Line1" & @CRLF) ; The CRLF at the end is a line break
FileWrite($file, "Line2")