Read in a number of characters from a previously opened text file.
FileRead ( "filehandle/filename" [, count] )
| filehandle/filename | The handle of a file, as returned by a previous call to FileOpen. Alternatively you may use a string filename as the first parameter. |
| count | [optional] The number of characters to read. See remarks. |
| Success: | Returns the binary/string read. @extended is set to the number of bytes/characters returned. |
| Special: | Sets @error to -1 if end-of-file is reached. |
| Failure: | Sets @error to 1 if file not opened in read mode or other error. |
Local $file = FileOpen("test.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in 1 character at a time until the EOF is reached
While 1
Local $chars = FileRead($file, 1)
If @error = -1 Then ExitLoop
MsgBox(0, "Char read:", $chars)
WEnd
FileClose($file)