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 Path||The path and filename for the file to be opened.|
|Mode Optional||The 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 does not 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, "Still Line1" & @CRLF) ; The CRLF at the end is a line break