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 12:19:58
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00451983
Message ID:
00452320
Views:
65
And there you have it! I talked to a colleague here who uses low-level file functions regularly. He also said that appending to a dbf is faster, but when writing the file out he uses fputs. He could not verify if a copy to or fputs is faster, its just a funcion of how the code is structured that decided the approach he took.

>>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.
>
>James,
>
>I interrupt the process. It took 14 sec. for 4000 records. So, for 5 mln. records it would take ~4h. It's too much for me to wait :)
>
>
>lcFile='J:\phone\phone1100.txt' && 382MB file
>*!*     lnSec=seconds()
>*!*     create cursor dummy (f1 l) && Smallest possible to speed up
>*!*     append from (lcFile) type sdf
>*!*     nLines = reccount()
>*!*     use in 'dummy'
>*!*     ?seconds()-lnSec, nLines
>set escape on
>on escape halt=.t.
>lnSec=seconds()
>local lnHandle, lnCount, m.halt
>m.halt=.f.
>*-----------------------------------------
>*-- Get a file handle
>*-----------------------------------------
>lnHandle = fopen(lcFile,12)
>?lnHandle
>*-----------------------------------------
>*-- Move to the first line
>*-----------------------------------------
>=FSEEK(lnHandle, 0, 0)
>*-----------------------------------------
>*-- Loop through each line and count
>*-----------------------------------------
>lnCount = 0
>do while !feof(lnHandle) and !m.halt
>    if m.halt
>       exit
>    endif
>     lnCount = lnCount + 1
>     =fgets(lnHandle)
>enddo
>?seconds()-lnSec, lnCount
Previous
Reply
Map
View

Click here to load this message in the networking platform