IsEndOfFile Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the IsEndOfFile method to verify whether the cursor position is at the end of the file.

Declaration

aqTextFileObj.IsEndOfFile()

aqTextFileObj An expression, variable or parameter that specifies a reference to an aqTextFile object
Result Boolean

Applies To

The method is applied to the following object:

Result Value

True if the end of the file is reached, and False otherwise.

Example

The code below demonstrates how you can read data from a text file and post it to the test log.

JavaScript, JScript

function ReadTextFromFile()
{
  var sPath = "D:\Files\MyFile.txt";

  // Opens the specified file for reading
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode);
  Log.Message("File by lines:");

  // Reads text lines from the file and posts them to the test log
  while(! myFile.IsEndOfFile())
  {
    s = myFile.ReadLine();
    Log.Message(s);
  }

  // Closes the file
  myFile.Close();
}

Python

def ReadTextFromFile():
  sPath = "D:\Files\MyFile.txt"
  # Opens the specified file for reading
  myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode)
  Log.Message("File by lines:")
  # Reads text lines from the file and posts them to the test log
  while not myFile.IsEndOfFile():
    s = myFile.ReadLine()
    Log.Message(s)
  # Closes the file
  myFile.Close()

VBScript

Sub ReadTextFromFile
  Dim sPath
  sPath = "D:\Files\MyFile.txt"

  ' Opens the specified file for reading
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode)
  Log.Message("File by lines:")

  ' Reads text lines from the file and posts them to the test log
  While Not myFile.IsEndOfFile()
    s = myFile.ReadLine()
    Log.Message(s)
  WEnd

  ' Closes the file
  Call myFile.Close()
End Sub

DelphiScript

procedure ReadTextFromFile;
var sPath, myFile;
begin
  sPath := 'D:\Files\MyFile.txt';

  // Opens the specified file for reading
  myFile := aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode);
  Log.Message('File by lines:');

  // Reads text lines from the file and posts them to the test log
  while not myFile.IsEndOfFile() do
    begin
      s := myFile.ReadLine();
      Log.Message(s);
    end;

  // Closes the file
  myFile.Close();
end;

C++Script, C#Script

function ReadTextFromFile()
{
  var sPath = "D:\Files\MyFile.txt";

  // Opens the specified file for reading
  var myFile = aqFile["OpenTextFile"](sPath, aqFile.faRead, aqFile.ctUnicode);
  Log["Message"]("File by lines:");

  // Reads text lines from the file and posts them to the test log
  while(! myFile.IsEndOfFile())
  {
    s = myFile["ReadLine"]();
    Log["Message"](s);
  }

  // Closes the file
  myFile["Close"]();
}

See Also

Working With Files From Scripts
IsEndOfLine Method

Highlight search results