|
|
|
| 13 February 2002 | GetLineCount() |
| Author | New Mexico Mark (wmarkh@aol.com) |
| Action | Counts the lines in a given text file. |
| Syntax | GetLineCount (FileSpec) |
| Parameters | |
| Remarks | Keep in mind that KiXtart reads in complete files, so mileage may vary on larger files. |
| Returns | Integer with number of lines in the file or -1 for error. |
| Dependencies | None. But function uses 7 for file number. Make sure there are no conflicts with open files in your script. |
| Examples |
$Lines=GetLineCount('c:\temp\myfile.txt')
'Your file has ' + $Lines + ' lines.' ?
|
| Source |
FUNCTION GetLineCount ($sfilespec)
; $sFileSpec is a string containing a file specification
;
; GetLineCount() returns an integer with the number of lines in the file or -1 if there is an error.
DIM $vtmp, $ifilenum
$sfilespec = '' + $sfilespec
$ifilenum = 7
$getlinecount = -1
IF Exist($sfilespec)
IF Open($ifilenum,$sfilespec) = 0
$getlinecount = 0
$vtmp = ReadLine($ifilenum)
WHILE @error = 0
$getlinecount = $getlinecount + 1
$vtmp = ReadLine($ifilenum)
LOOP
$vtmp = Close($ifilenum)
ENDIF
ENDIF
ENDFUNCTION ; - GetLineCount -
|
|
|
|