ramseier Posted February 13, 2008 Share Posted February 13, 2008 Hello, I have a textfile with csv-data which has 604 lines (Ultraedit). If i use _FileCountLines($filename) it delivers the following value: "-351489" If i read the file into an array, the file has only 261 lines. I've tried it as it is and converted unix2dos. Every other file delivers correct filecounts. Whats wrong with this file? Link to comment Share on other sites More sharing options...
James Posted February 13, 2008 Share Posted February 13, 2008 (edited) Can we see the file and code you are using? Try this: #include <File.au3> $File = FileOpenDialog("_FileCountLines", @ScriptDir, "All Files(*.*)") MsgBox(0, "_FileCountLines", _FileCountLines($File)) Probably makes no difference. Edited February 13, 2008 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
SamoV Posted February 28, 2008 Share Posted February 28, 2008 I had the same problem. One legacy program is outputting test results into csv file, and I'm monitoring this file and using _FileCountLines and FileReadLine to get last line. For small files this was working good, but when file gets larger, _FileCountLines start to return minus values. I'm using this piece of code to do this task now: CODE $f = FileRead("RESULTS.CSV") $p1 = StringInStr($f, Chr(13) & Chr(10), 1, -2) $p2 = StringInStr($f, Chr(13) & Chr(10), 1, -1) MsgBox(0, "String", StringMid($f, $p1, $p2 - $p1)) Maybe it will be of some help to you. Link to comment Share on other sites More sharing options...
rmarino Posted February 28, 2008 Share Posted February 28, 2008 I have the same problem, if I use the function against an excel file it outputs negative numbers, but if I output the file to a txt file it works fine. Link to comment Share on other sites More sharing options...
weaponx Posted February 28, 2008 Share Posted February 28, 2008 Perhaps there are some hidden characters in the file that you aren't seeing. Maybe you can open the file in SciTe and click View > End Of Line, or open it in Word and enable code view. Link to comment Share on other sites More sharing options...
Tacomas Posted July 3, 2013 Share Posted July 3, 2013 Sorry for bumping such an old thread but I used this function for the first time today and also found that it reported the wrong number of lines for all the files I tested it with. As an example I got 2 plain text files, 1st file has 888 lines (according to Notepad++) but _FileCountLines() returned 882. 2nd file has 959 lines but _FileCountLines() returned 953. I was thinking that the function doesn't count empty lines but even after removing the empty lines the reported number of lines was wrong so I wrote my own replacement which gives me the correct result, at least, for the files I am currently working with (plain ANSI text, DOSWindows). Func _FCntLn($sFile) Local $ret = 0, $hFile = FileOpen($sFile, 0) While 1 FileReadLine($hFile) If @error = -1 Then ExitLoop $ret += 1 WEnd FileClose($hFile) Return $ret EndFunc Link to comment Share on other sites More sharing options...
Mat Posted July 3, 2013 Share Posted July 3, 2013 Sorry for bumping such an old thread but I used this function for the first time today and also found that it reported the wrong number of lines for all the files I tested it with. As an example I got 2 plain text files, 1st file has 888 lines (according to Notepad++) but _FileCountLines() returned 882. 2nd file has 959 lines but _FileCountLines() returned 953. I was thinking that the function doesn't count empty lines but even after removing the empty lines the reported number of lines was wrong so I wrote my own replacement which gives me the correct result, at least, for the files I am currently working with (plain ANSI text, DOSWindows). Func _FCntLn($sFile) Local $ret = 0, $hFile = FileOpen($sFile, 0) While 1 FileReadLine($hFile) If @error = -1 Then ExitLoop $ret += 1 WEnd FileClose($hFile) Return $ret EndFunc That's a very slow way to do it. The _FileCountLines function does not include any trailing space. That could be the source of the discrepancy. TheSaint 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
AZJIO Posted July 3, 2013 Share Posted July 3, 2013 (edited) $sPath = @ScriptFullPath MsgBox(0, 'Yes?', UBound(StringRegExp(FileRead($sPath), '(\r\n|\r|\n)', 3)) + 1) Use the Forum search Edited July 3, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
TheSaint Posted July 4, 2013 Share Posted July 4, 2013 That's a very slow way to do it. The _FileCountLines function does not include any trailing space. That could be the source of the discrepancy. I've used that function a lot, and can confirm that the only discrepancies that I've ever come across, have indeed been trailing space after the last text line. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Tacomas Posted July 4, 2013 Share Posted July 4, 2013 (edited) That's a very slow way to do it. The _FileCountLines function does not include any trailing space. That could be the source of the discrepancy. No it's not, it's even faster (at least for small files). _FCntLn = 888 lines (4.82992862113775 ms) _FileCountLines = 882 lines (4.980045943599 ms) _FCntLn = 959 lines (3.82799172276179 ms) _FileCountLines = 953 lines (6.60824151798637 ms) _FCntLn = 959 lines (3.83261071729906 ms) _FileCountLines = 953 lines (6.03933535747938 ms) _FCntLn = 888 lines (3.27640679176957 ms) _FileCountLines = 882 lines (4.91884426598018 ms) Times taken using TimerInit() and TimerDiff(). If trailing whitespace is causing this function to report the wrong number of lines then this might need to be fixed or at least mentioned in the help file. Edited July 4, 2013 by Tacomas 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