Get the number of strings of a specified text file. The end of the line is a set of symbols CRLF (ASCII #13#10).

 

Syntax

function GetTextFileLinesCount(sFileNameWithPath: string; iEncodingType: integer): int64;

 

Parameters and return values

Parameter

Type

Value

sFileNameWithPath

string

a name of a text file with a full path to it;

iEncodingType

integer

file encoding type, number.

 

Function result

-1        file does not exist;

-2        file access error;

>=0        a number of lines in a text file.

 

Example


const
  FILE_NAME = 'F:\Doc\MyChatJSONprotocol.txt';
var
  iCount: int64;
begin
  iCount := GetTextFileLinesCount(FILE_NAME, 0);
  
    if iCount = -1 then mLogScript('File not found!', '')
      else mLogScript(IntToStr(iCount) + ' lines total', '');
end.


Script work result

[16:32:20] (Log "GetTextFileLinesCount"): 7015 lines total

[16:32:20] (Run "GetTextFileLinesCount"): Script operation time: 30 ms

[16:32:20] (Run "GetTextFileLinesCount"): Script done successfully.

 

See also

IntToStr

mLogScript