Jump to content
Sign in to follow this  
Davman

File lines

Recommended Posts

Davman

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.

Share this post


Link to post
Share on other sites
Davman

come on, i know you guys want to answer this before i leave work today...


Sitting comfortably behind the code.

Share this post


Link to post
Share on other sites
Davman

Anyone got any ideas, or should this be put onto the wishlist?


Sitting comfortably behind the code.

Share this post


Link to post
Share on other sites
sugi

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

Share this post


Link to post
Share on other sites
Davman

Yeah, i ended up writing it like that in the end.


Sitting comfortably behind the code.

Share this post


Link to post
Share on other sites
Andre

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!

Share this post


Link to post
Share on other sites
Davman

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.

Share this post


Link to post
Share on other sites
Valik

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).

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×