Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Count # of lines in a Textfile FAST !
Message
De
12/09/2008 16:31:09
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01347163
Message ID:
01347225
Vues:
20
This message has been marked as a message which has helped to the initial question of the thread.
>Hey Gang...
>
>Any quick way to Count the number of Lines in a Text File?
>
>I have some data coming in a delimited textfile. Each line represents a normal record.
>
>What I did was to open the file, and loop through each line of data and keep track of how many times this was done until I reach the end of the file.... like this...
>
>
>*Count the number of records in the file...
>     lnNumOfRecords = 0
>     DO WHILE !FEOF(lnHandle)
>          lcText = ALLTRIM(FGETS(lnHandle))
>          lnNumOfRecords = lnNumOfRecords + 1
>     ENDDO
>     filetop  = FSEEK(lnHandle, 0)				&& Move pointer to BOF
>
>
>
>Kinda slow with a LARGE file....
>
>I needed to know how many lines, because with this known, I can then use this info in a Thermometer when I REALLY process the text file.

Maybe you don't need to count lines at all. You can count bytes - use fSeek() to get the current position, you know the total length of the file, and there you are.

Also, if your file generally has less than 65000 lines (seeing that you are using VFP8), you can simply

nLines=alines(aRows, filetostr(lcYourFileName))

OTOH, if your file has more records but you can be sure that no record is longer than 255 bytes,

create cursor crsRows (cLine c(254))
append from (lcYourFileName) type SDF

and then you just scan through this cursor, and chop cRow just like you'd do with lcText above. If your lines are longer, then

create cursor crsRows (cLine1 c(250), cLine2 c(250), cLine3 c(250), ...)
append from (lcYourFileName) type SDF

and then your lcText=trim(cLine1+cline2+cline3+...) for each record.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform