Re: Reading txt file line by line
Re: Reading txt file line by line
- Subject: Re: Reading txt file line by line
- From: JJ <email@hidden>
- Date: Wed, 17 Oct 2001 04:41:01 +0200
>
Hello all.
>
I have a rather large text file that I'd like to read into line by line.
>
So far I have the following:
>
>
on open fileList
>
repeat with oneFile in fileList
>
set oneFile to oneFile as string
>
tell application "Finder"
>
set fileName to name of file oneFile as text
>
if not (fileName ends with ".txt") then
>
display dialog "Cannot process file " & fileName & " because
>
it is not a text file!" buttons "OK" default button 1 with icon 2
>
else
>
set OPENFILE to open for access file oneFile
>
set oneLine to read OPENFILE until return as {text} using
>
delimiter {tab, return}
>
>
end if
>
end tell
>
end repeat
>
end open
>
>
The part that I want to use is the:
>
set oneLine to read OPENFILE until return as {text} using
>
delimiter {tab, return}
>
But I want to repeat thru every line without having to read the entire file
>
into my variable. What I am asking is after getting the first line returned
>
to me, how do I then do the same line of code for the 2nd, 3rd, 4th, etc....
repeat
try
set file_contents to read OPENFILE for 100 from x
on error
set last_file_contents to (read OPENFILE from (theLength - x) to
theLength)
exit repeat
end try
set x to x + 100
end repeat