Modify

Opened 17 years ago

Closed 17 years ago

#149 closed Bug (No Bug)

FileRead does not return EOF but does return @Error =0, an undocumented state

Reported by: oblique Owned by:
Milestone: Component: AutoIt
Version: 3.2.10.0 Severity:
Keywords: FileRead error Cc:

Description

;FileRead(filehandle or "filename" [, count])
;Failure(s): 
;EOF is not set when using 'filename' (default is to read entire file which I would expect to set EOF
;function returns @error = 0 which is an undocumented value
;########
;Code below will demonstrate the problem, and can be used to test that the problem has been fixed.
;any text file can be used to demonstrate the problem
;########
;prove FileOpen is good, and EOF is found
$file = FileOpen("anytext.txt", 0)
If $file = -1 Then
	MsgBox(0, "Error", "Unable to open file.")
	Exit
EndIf
While 1
	$chars = FileRead($file, 10000)
	If @error = -1 Then ExitLoop
	MsgBox(0, "Char read and EOF set:", $chars)
Wend
FileClose($file)

;show error
$fileR = FileRead("anytext.txt")
MsgBox(0,"Entire file is read", "Chars:"&@CRLF&$fileR)
Select
	Case @error = -1
		MsgBox(0,"","pass; SPECIAL: @Error="&@error&" -1 = EOF is reached")
	Case @error = 1
		MsgBox(0,"","FAIL; SPECIAL: @Error="&@error&" 1 = file not opened in read mode or other error, NOT POSSIBLE IN THIS TEST")
	Case @error = 2
		MsgBox(0,"", "FAIL; SPECIAL: @Error="&@error&" 2 = count not defined for file open in raw read mode, NOT POSSIBLE IN THIS TEST")
	Case Else
		MsgBox(0,"","FAIL; SPECIAL: @Error="&@error&" UNEXPECTED - @Error is set to 0 not -1 when FileRead is executed (default is entire file)")
EndSelect

Exit}}}

Change History (2)

comment:1 Changed 17 years ago by Valik

Your test is never going to return anything other than 0 because you destroy @error.

Anyway, ignoring that. Do you really need the function to set @error to -1 when you don't use a file handle? It seems kind of pointless to me.

comment:2 Changed 17 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

In fact your fileread is reading the entire file so as the reading is successful @error is set to 0. NOBUG
if you were using the count EOF can be signalled if you try to read after the last data.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.