BBS: Inland Empire Archive
Date: 04-16-92 (19:55) Number: 174
From: PAUL LEONARD Refer#: NONE
To: ZACK JONES Recvd: NO
Subj: File Size Conf: (2) Quik_Bas
On or about <Apr 15 16:46>, Zack Jones (1:387/905.1) scribbled:
ZJ> I'm trying to find the fastest way for me to find the length of a file.
ZJ> I know LOF shows the size in bytes. What I want to know is how many
ZJ> lines there are in an ASCII text file that I open. I
ZJ> can count the number
ZJ> of lines as I read the file using a line input statement, but is there a
ZJ> faster way than using a do while loop to read the file and count it line
ZJ> by line? All help is greatly appreciated.
CONST recsize = 1024
DIM rec AS STRING * recsize
delimiter$ = CHR$(13)
INPUT "File to read"; in$
OPEN in$ FOR RANDOM AS #1 LEN = recsize
DO UNTIL EOF(1)
GET #1, , rec$
delimiter% = INSTR(delimiter% + 1, rec$, delimiter$)
IF delimiter% THEN lines% = lines% + 1
LOOP WHILE delimiter%
PRINT in$; " has"; lines%; "lines."
Not all that elegant, but it's faster than sequential
input. Even with a small buffer like 1K (the 1024 record
size), on average it read a 68K text file (about 1500
lines) in about 0.5 seconds while sequential LINE INPUT
took about 3.3 seconds.
(I saw a great tagline today - "Every now and then an
innocent man is sent to the legislature.")
--- msged 2.07
* Origin: PTL Pointwork (1:140/23)