Sure
The FLL ... code is below. (And I am in no way fluent with C++ or FLL's so
may be much better ways ..)
You 'll need a few other components but if you chase up how to create an FLL
then you'll have it sorted.
Once below is built into FLL it can be used directly in VFP.
Viz. SET library to ". fll" | lnLines =
FllGetFileLineCount(<FilePath>)
void GetFileLineCount(ParamBlk *parm)
{
#define p0 (parm->p[0].val)
((char *)_HandToPtr(p0.ev_handle))[p0.ev_length] = '\0';
char *srcFileName = (char *)_HandToPtr(p0.ev_handle) ;
FILE *istream = fopen(srcFileName, "rb");
if (istream == 0)
{
_RetInt(-1, 10);
}
int numLines = 0;
const int len = 8192;
char buf[8192];
do
{
if( feof(istream))
{
break;
}
int nBytesRead = fread(buf, 1, len, istream);
if(nBytesRead <= 0)
{
break;
}
for(int i = 0; i < nBytesRead; i++)
{
if(buf[i] == '\n')
numLines++;
}
} while(1);
fclose(istream);
_RetInt(numLines, 10);
}
FoxInfo vfpUtilFLLInfo[] =
{
{"FllGetFileLineCount", (FPFI) GetFileLineCount, 1, "C"}
};
#ifdef __cplusplus
extern "C"
#endif
FoxTable _FoxTable = {
(FoxTable *)0, sizeof(vfpUtilFLLInfo)/sizeof(FoxInfo),
vfpUtilFLLInfo
};
-----Original Message-----
From: ProfoxTech [mailto:[email protected]] On Behalf Of Gianni
Turri
Sent: Saturday, 29 April 2017 2:24 AM
To: [email protected]
Subject: Re: Getting count of rows in a text file -- best approach?
Test file of 1.67 GB correctly managed by FSO but not by VFP9 SP2 that gives
Error 43 (There is not enough memory to complete this operation).
Test file of 5.31 GB correctly managed by FSO but not by VFP9 SP2 that gives
Error 1103 (Invalid seek offset).
FSO method counts chr(10) / LF characters.
alines() by default counts the occurrences of chr(10) plus the occurrences
of chr(13) minus the occurrences of chr(13) + chr(10)
Please tell us more about the FLL and the code you used!
Gianni
On Sat, 29 Apr 2017 01:15:06 +1000, "Darren" <
<mailto:[email protected]> [email protected]> wrote:
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>
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:[email protected]>
mailto:[email protected]] On Behalf Of Gianni Turri
Sent: Friday, 28 April 2017 11:39 PM
To: <mailto:[email protected]> [email protected]
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" <
<mailto:[email protected]> [email protected]> wrote:
>Forget my comment, I've tested it and works beautifully :)
>
>2017-04-28 15:24 GMT+02:00 Fernando D. Bozzo < <mailto:[email protected]>
[email protected]>:
>
>> 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 < <mailto:[email protected]>
[email protected]>:
>>
>>> On Thu, 27 Apr 2017 17:12:49 +0200, "Fernando D. Bozzo" <
>>> <mailto:[email protected]> [email protected]> 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->
http://stackoverflow.com/questions/7416553/function-to-count-number-
>>> of-lines-in-a-text-file
_______________________________________________
Post Messages to: <mailto:[email protected]> [email protected]
Subscription Maintenance: <http://mail.leafe.com/mailman/listinfo/profox>
http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list:
<http://mail.leafe.com/mailman/listinfo/profoxtech>
http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: <http://leafe.com/archives/search/profox>
http://leafe.com/archives/search/profox
This message:
<http://leafe.com/archives/byMID/profox/p0q6gc9cisfda2hrsaf5vsi0jmqnap1emi@4
ax.com>
http://leafe.com/archives/byMID/profox/p0q6gc9cisfda2hrsaf5vsi0jmqnap1emi@4a
x.com
** 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.
Report [OT] Abuse:
<http://leafe.com/reportAbuse/[email protected]>
http://leafe.com/reportAbuse/[email protected]
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: [email protected]
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/[email protected]
** 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.