LinesCount Property

Applies to TestComplete 15.68, last modified on October 03, 2024

Description

Use the LinesCount property to get the number of lines in a text file. To determine the current line or select a specific line, use the Line property.

Declaration

aqTextFileObj.LinesCount

Read-Only Property Integer
aqTextFileObj An expression, variable or parameter that specifies a reference to an aqTextFile object

Applies To

The property is applied to the following object:

Property Value

The number of lines in the specified text file.

Remarks

Lines are counted based on Windows line breaks – CR+LF (\r\n or 0x0D0A). CR or LF alone is not recognized as a line break.

Example

The following example reads a file by lines and posts each line to the test log:

JavaScript, JScript

function Test()
{
  var fileName = "C:\\Files\\MyFile.txt";

  var fileObj = aqFile.OpenTextFile(fileName, aqFile.faRead, aqFile.ctANSI);
  Log.Message(fileObj.LinesCount);

  fileObj.Close();
}

Python

def Test():
  fileName = "D:\\Files\\MyFile.txt"
  fileObj = aqFile.OpenTextFile(fileName, aqFile.faRead, aqFile.ctANSI)
  Log.Message(fileObj.LinesCount)
  fileObj.Close()

VBScript

Sub Test
  Dim fileName, fileObj
  fileName = "C:\Files\MyFile.txt"

  Set fileObj = aqFile.OpenTextFile(fileName, aqFile.faRead, aqFile.ctANSI)
  Call Log.Message(fileObj.LinesCount)

  Call fileObj.Close
End Sub

DelphiScript

procedure Test;
var fileName, fileObj;
begin
  fileName := 'C:\Files\MyFile.txt';

  fileObj := aqFile.OpenTextFile(fileName, aqFile.faRead, aqFile.ctANSI);
  Log.Message(fileObj.LinesCount);

  fileObj.Close;
end;

C++Script, C#Script

function Test()
{
  var fileName = "C:\\Files\\MyFile.txt";

  var fileObj = aqFile["OpenTextFile"](fileName, aqFile.faRead, aqFile.ctANSI);
  Log["Message"](fileObj["LinesCount"]);

  fileObj["Close"]();
}

See Also

Working With Files From Scripts
Line Property

Highlight search results