Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How get the Number of Lines from a text file
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00451983
Message ID:
00452308
Views:
74
>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
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform