Hi;
Is there a way to specify to read the last line in a text file? I can't use a specific line number cause lines will get added.
EQ. ret$ = FILE.READ$(MYFILE.TXT, LAST_LINE) (would be nice)
Thanks Zim
How to specify last line in "File.read$"
Re: How to specify last line in "File.read$"
I got this to work:
Code: [Local Link Removed for Guests]
lineNum = 1
FOR i=1 to 50
Dt$ = file.read$("/test.txt", lineNum)
dt = val(Dt$)
if dt <> 0 then
lineNum = (lineNum + 1)
else
lineNum = (lineNum - 1)
EXIT FOR
endif
next i
Dt$ = file.read$("/test.txt", lineNum)
wlog Dt$
- PeterN
- Posts: 399
- Joined: Mon Feb 08, 2021 7:56 pm
- Location: Krefeld, Germany
- Has thanked: 189 times
- Been thanked: 221 times
- Contact:
Re: How to specify last line in "File.read$"
I had the same problem with slow reading when searching for the actual line number.
So I narrowed down the first empty line first in large steps and then in finer steps to find the highest line number
So I narrowed down the first empty line first in large steps and then in finer steps to find the highest line number
Code: [Local Link Removed for Guests]
GET_MAX_LINENUMBER_FROM_FILE:
'=========================================================================
filename$="/MY_FILE.TXT"
' my file has a content of more than 400 lines with at least a three digit linenumber and some text
' reading it line by line last about 15s.
'So I shortened that a bit
LINE_STEP = 50
MAX_LINENUMBER = 0
WLOG "Please wait ###########################################"
if file.exists(filename$) then
' first in rough steps up to behind the file boundary, because it reads very very slowly in steps of one.
do
MAX_LINENUMBER = MAX_LINENUMBER + LINE_STEP
XX$=FILE.READ$(filename$,MAX_LINENUMBER)
wlog "ROUGH TESTING ----> MAX_LINENUMBER=",MAX_LINENUMBER, " in file : "; filename$
loop until len(XX$) < 6
MAX_LINENUMBER = MAX_LINENUMBER - LINE_STEP
'now starting from the determined rough position, read individual lines
do
MAX_LINENUMBER = MAX_LINENUMBER + 1
XX$=FILE.READ$(filename$,MAX_LINENUMBER)
loop until len(XX$) < 6
MAX_LINENUMBER = MAX_LINENUMBER - 1
WLOG "###########################################"
wlog "MAX_LINENUMBER=",MAX_LINENUMBER, " in file : "; filename$
endif
return