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 10:28:23
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00451983
Message ID:
00452217
Views:
68
>>>>>Let's not squabble. Some good suggestions were made here. Everyone knows that there are nice ways to Sunday to accomplish the same task in VFP. Performance is often negligible between different approaches.
>>>>
>>>>Thanks for the new word for me, James :) Now, I didn't intend to squabble. My point was that not all suggestions could be applied to huge files. That's it.
>>>
>>>Nadya,
>>>
>>>The text file you are talking about would have to be truly huge! In most situations I don't think it would be a problem:
>>>
>>>Maximum # of characters per character string or memory variable--16,777,184
>>
>>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
>
>My mistake, I meant FGETS(), and I never encountered the bug. I'll try to find out if it is fixed SP4 and post.

Here it is:

A minor behavior change was necessary for the FGETS() function related to Knowledge Base article.

Q221747: (C0000005 Fatal Error Passing FGETS() a String >256 chars). The optional nBytes parameter now has a maximum value of 8192. By definition, FGETS() only returns bytes up to a carriage return if one is encountered before the parameter value is reached.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform