AutoIt FileRead Function

The FileRead function is used in combination with FileOpen to read files.

2188 views

Edited: 2017-12-19 17:42

The AutoIt FileRead function can be used to read files, and save their contents into a variable for later use.

If a filename is used instead of a file handle, the file will be opened and closed doing function call. This will be slower than using file handles when parsing larger files, so it might be better to use file handles.

FileRead can be used when working with custom configuration files for your scripts. An alternative is to use .ini files in combination with AutoIt's ini-functions. I.e: IniRead and IniWrite

Loading a file with FileRead

To read a file, it should first be opened for reading using FileOpen, then we can load it into a variable using FileRead. In the below example, the content of the loaded file is displayed using a message box.

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

    $FileContent = FileRead($file)
    MsgBox(0, "Content:", $FileContent)

FileClose($file)

Parameters

filenameHandle of previously opened file.
count optionalThe number of characters to read. Reads the entire file by default.

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials