_Main()
Func _Main()
Local $File
Local $sum
$File = @ScriptDir & "\test.txt" ;<--你要读的文件
$sum = _CountLines($File)
If $sum = -1 Then
MsgBox(0, "错误", "不能打开文件")
Else
MsgBox(0, "读取完毕", $File & " 共" & $sum & "行")
EndIf
Exit
EndFunc ;==>_Main
Func _CountLines($File)
Local $m = 0, $t
Local $FileHandle
$FileHandle = FileOpen($File, 0)
If $FileHandle = -1 Then
Return -1
Else
While 1
$t = FileReadLine($FileHandle)
If @error = -1 Then
ExitLoop
Else
$m = $m + 1
EndIf
WEnd
EndIf
FileClose($FileHandle)
Return $m
EndFunc ;==>_CountLines
|