From MiniScript Wiki
Jump to navigation Jump to search

The atEnd method of the FileHandle class returns true after attempting to read past the end of the file.

Note that atEnd is not true after the last successful read, nor is it true at the beginning of an empty file. It only reports the condition that the last attempted read failed because there was no more data. This is explained (in reference to the standard C function feof) here.

For this reason, instead of using atEnd in most cases, you should simply check for the read or readLine method to return null, like so:

reader ="fileToRead.txt", "r")
writer ="fileToWrite.txt", "w")

// Copy the lines from one to the other, while changing to upper case.
while true
	line = reader.readLine
	if line == null then break
	writer.writeLine line.upper
end while