;1:
Func _FileCountLinesEx($sFile)
If Not FileExists($sFile) Or StringInStr(FileGetAttrib($sFile), "D") Then Return SetError(1, 0, 0)
Local $aLines = StringRegExp(FileRead($sFile), "(\n)", 3)
If Not IsArray($aLines) Then Return SetError(2, 0, 0)
Return UBound($aLines)+1
EndFunc
;2:
Func _FileCountLinesEx($sFilePath, $iCountLastLine=1)
Local $iCountLines = 0
Local $sFRead = FileRead($sFilePath)
If @error = -1 Then Return SetError(1, 0, 0) ;The file is empty
If @error <> 0 Then Return SetError(2, 0, 0) ;File not exists or other "Read" error.
If Not $iCountLastLine Then $sFRead = StringStripWS($sFRead, 2)
$sFRead = StringReplace($sFRead, @CRLF, "")
$iCountLines += @extended
$sFRead = StringReplace($sFRead, @CR, "")
$iCountLines += @extended
StringReplace($sFRead, @LF, "")
$iCountLines += @extended
Return $iCountLines + 1
EndFunc