Update to below. Using FSO doesn't crash - I missed the parameters ... 8,.F.) but it is somewhat slower.
59.3775 seconds using the OpenTextFile(<filename>, 8, .F.) approach and 164.4686 seconds using the AtEndOfStream() | SkipLine approach. -----Original Message----- From: ProfoxTech [mailto:profoxtech-boun...@leafe.com] On Behalf Of Darren Sent: Saturday, 29 April 2017 1:15 AM To: profoxt...@leafe.com Subject: RE: Getting count of rows in a text file -- best approach? Many ways to do this. I've compared 3. With a text file 350Mb | 5.3Million lines . Each method reported same # of lines. Timing done with high resolution timers so reasonably accurate. ... 1. C++ FLL 0.4064 seconds 2. C# .NET 1.2779 seconds : Tip on how to do this is at http://www.tek-tips.com/faqs.cfm?fid=3836 3. FSO 7.3874 seconds : (using OpenTextFile etc.) With a text file 2.6GB file. | 42 Million lines. FSO died - reported no lines and finished in 0.0002 seconds - other two methods reported accurately. 1. C++ FLL 3.2426 seconds 2. C# .NET 10.0600 seconds 3. FSO 0.0002 seconds : FAILED So I'd guess if you are doing many of these and time is an issue then perhaps a FLL approach might be beneficial. Certainly if file is large enough (probably hits the 2Gb limit in VFP) then FSO is not an option. -----Original Message----- From: ProfoxTech [mailto:profoxtech-boun...@leafe.com] On Behalf Of Gianni Turri Sent: Friday, 28 April 2017 11:39 PM To: profoxt...@leafe.com Subject: Re: Getting count of rows in a text file -- best approach? Ok. Anyway this is the slower method: loFSO = createobject("Scripting.FileSystemObject") loFile = loFSO.OpenTextFile(m.filename, 1) do while ! loFile.AtEndOfStream() loFile.SkipLine() enddo ? loFile.Line -1 Gianni On Fri, 28 Apr 2017 15:29:48 +0200, "Fernando D. Bozzo" <fdbo...@gmail.com> wrote: >Forget my comment, I've tested it and works beautifully :) > >2017-04-28 15:24 GMT+02:00 Fernando D. Bozzo <fdbo...@gmail.com>: > >> Gianni, you skipped something very important, the part that skip the >> lines so the Line property is updated: >> >> 'Skip lines one by one Do While txsInput.AtEndOfStream <> True >> txsInput.SkipLine ' or strTemp = txsInput.ReadLineLoop >> >> 2017-04-28 15:08 GMT+02:00 Gianni Turri <gianni...@gmail.com>: >> >>> On Thu, 27 Apr 2017 17:12:49 +0200, "Fernando D. Bozzo" < >>> fdbo...@gmail.com> wrote: >>> >>> >Hi Mike: >>> > >>> >A very fast method is using the FileSystemObject: >>> > >>> >loFSO = CREATEOBJECT("Scripting.FileSystemObject") >>> >loFile1 = loFSO.OpenTextFile(lcArchivo1, 1) >>> > >>> >Look at the syntax on Microsoft web site for the read method. >>> >It does not have the limitation of VFP's fread/fgets >>> >>> loFSO = createobject("Scripting.FileSystemObject") >>> >>> loFile = loFSO.OpenTextFile(m.filename, 8, .f.) ? loFile.Line -1 >>> >>> This method overcome VFP memory / file size limits. >>> >>> Source: >>> http://stackoverflow.com/questions/7416553/function-to-count-number- >>> of-lines-in-a-text-file [excessive quoting removed by server] _______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/002a01d2c038$01e76850$05b638f0$@ozemail.com.au ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.