Jump to content

Recommended Posts

Posted

Any way to read the total amount of lines in a file?

I.e, without scanning through each line and increasing a variable until EOF.

Sitting comfortably behind the code.

Posted

There's no easier way than to read the whole file and count the lines while reading... so there is no sense in putting this on the wishlist. Of course this would be a bit faster when it was builtin but I don't think the small difference will matter.

Func FileCountLines($File)
    Local $FH, $Lines = -1
    $FH = FileOpen($File, 0)
    If $FH = -1 Then
        SetError(1)
        Return 0
    EndIf
    SetError(0)
    While Not @error
        $Lines = $Lines + 1
        FileReadLine($FH)
    Wend
    SetError(0)
    Return $Lines
EndFunc  ;==>FileCountLines
Posted

Hi,

I Think that technically it's not possible to do it another way :ph34r:

What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
Posted

mmm... but it could be a built in function... if (like me), you have written in languages (if you want to call it that) like the mIRC scripting language, you know of the $lines() identifier, which will give you the amount of lines in a file.

Sitting comfortably behind the code.

Posted

But the problem is, if it's built in, it'll look identical (Except using C's syntax). Something that simple, surely, can be left up to the script-writer to write. Besides, there is a function in the standard library called _FileCountLInes which already does this (I think this is included in the latest stable build, as well).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...