Re: applescript-users digest, Vol 2 #1203 - 13 msgs
Re: applescript-users digest, Vol 2 #1203 - 13 msgs
- Subject: Re: applescript-users digest, Vol 2 #1203 - 13 msgs
- From: "Marc K. Myers" <email@hidden>
- Date: Tue, 16 Oct 2001 23:00:11 -0400
- Organization: [very little]
email@hidden wrote:
>
>
Send applescript-users mailing list submissions to
>
email@hidden
>
>
To subscribe or unsubscribe via the World Wide Web, visit
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
or, via email, send a message with subject or body 'help' to
>
email@hidden
>
>
You can reach the person managing the list at
>
email@hidden
>
>
When replying, please edit your Subject line so it is more specific
>
than "Re: Contents of applescript-users digest..."
>
>
Today's Topics:
>
>
1. Reading txt file line by line (Jeff Horton)
>
2. Quark 4.11 + OS X 10.1 = ? (Jason Toews)
>
3. Re: The Script Not Taking New Content From Clipboard...... (Sean Elfstrom)
>
4. Re: filename to bitmap (Brennan)
>
5. Re: hash arrays and other mysteries (Arthur J Knapp)
>
6. Re: filenametobitmap (email@hidden)
>
7. Re: Scripting RA in OS 9.2 (Cornwall)
>
8. Re: filename to bitmap (Shane Stanley)
>
9. RE: filename to bitmap (Zavatone, Alex)
>
10. Re: TERMINAL (garbanzito)
>
11. Dissatisfied with Display Dialog command (Irwin Poche)
>
12. Re: Dissatisfied with Display Dialog command (vectormation)
>
13. carrymehome (JJ)
>
>
--__--__--
>
>
Message: 1
>
Date: Tue, 16 Oct 2001 15:30:02 -0400
>
Subject: Reading txt file line by line
>
From: Jeff Horton <email@hidden>
>
To: <email@hidden>
>
>
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....
This works for me:
set fileID to (open for access file "Macintosh HD:Desktop Folder:test")
repeat
try
set theText to (read fileID until return as text)
-- do whatever with theText
on error
close access fileID
exit repeat
end try
end repeat
It returns one line with each read and falls through to the error
handler at eof.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[10/16/01 10:59:47 PM]