Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How get the Number of Lines from a text file
Message
From
12/12/2000 11:26:04
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00451983
Message ID:
00452267
Views:
73
>>James,
>>(not intending any squabble - .2 cents addition:)
>>In a previous reply I saw fread() to count lines.
>>Real problem with fread() it should be done byte by byte. The code I saw would error on first call to fread. fgets() could be used but it has a bug (cannot handle lines > 8192chars - maybe fixed in SP4?) OTOH for huge files (>1 billion lines < bg >) lowlevel sounds to be the only way (for >2Gb files I don't have an idea what OS response would be).
>>IMHO Barbara's original reply is the best with a slight modification (so it's faster than array approach too):
>>
>>
create cursor dummy (f1 l) && Smallest possible to speed up
>>append from (lcFile) type sdf
>>nLines = reccount()
>>use in 'dummy'
>>Best regards
>>Cetin
>
>Hi Cetin,
>
>I have a 382MB file. Dummy approach took 303.768 sec. Fgets approach took forever. I was not patient enough to wait, so I kill VFP. Right now I decide to repeat this test, this case with fgets(lnHandle,1). Seems to hang up also...
>
>Therefore your and David's approach is the fastest.

Nadya,

fgets(lnHandle,1) would read 1 bit at a time. That's why it is slow. fgets without the extra parameter would read the line until a carriage return is encountered. Actually this approach is ver fast, if you know you line won't exceed the 8,192 char limit.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform