Davman Posted July 21, 2004 Share Posted July 21, 2004 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. Link to comment Share on other sites More sharing options...
Davman Posted July 21, 2004 Author Share Posted July 21, 2004 come on, i know you guys want to answer this before i leave work today... Sitting comfortably behind the code. Link to comment Share on other sites More sharing options...
Davman Posted July 21, 2004 Author Share Posted July 21, 2004 Anyone got any ideas, or should this be put onto the wishlist? Sitting comfortably behind the code. Link to comment Share on other sites More sharing options...
sugi Posted July 21, 2004 Share Posted July 21, 2004 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 Link to comment Share on other sites More sharing options...
Davman Posted July 22, 2004 Author Share Posted July 22, 2004 Yeah, i ended up writing it like that in the end. Sitting comfortably behind the code. Link to comment Share on other sites More sharing options...
Andre Posted July 22, 2004 Share Posted July 22, 2004 Hi, I Think that technically it's not possible to do it another way What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel! Link to comment Share on other sites More sharing options...
Davman Posted July 22, 2004 Author Share Posted July 22, 2004 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. Link to comment Share on other sites More sharing options...
Valik Posted July 22, 2004 Share Posted July 22, 2004 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). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now