Re: Read a text file ...
Re: Read a text file ...
- Subject: Re: Read a text file ...
- From: John Delacour <email@hidden>
- Date: Sat, 19 Apr 2003 18:25:36 +0100
- Mac-eudora-version: 6.0a16
At 9:32 am -0700 19/4/03, Charles Heizer wrote:
>
Hello,
>
I'm writing a small applescript to scp a couple of files to a list
>
of hosts. I have crated a text file that has the info I need, it
>
looks like this -
>
>
myfirsthost.example.com;user;password
>
host2.example.com;user;password
>
>
So the file is delimited by semicolons. So I've been reading the
>
archives and I can't seem to figure out how to fill in the variables
>
in my script with the contents of each line.
You probably want something like this:
writeFile() -- make the sample file see (**) below
set fU to "/tmp/host.txt" -- UNIX pathname of file
set f to POSIX file fU -- file specification
set sStuff to {} -- in this case a list of lists
set sSeparator to ";"
set text item delimiters to sSeparator
open for access f
repeat
try
set lLine to read f until return
if lLine contains sSeparator then
set end of sStuff to text items of lLine
end if
on error
exit repeat
end try
end repeat
close access f
set text item delimiters to ""
sStuff
(**)
on writeFile()
set fU to "/tmp/host.txt"
set f to POSIX file fU
set s to "
myfirsthost.example.com;user;password
host2.example.com;user;password
"
open for access f with write permission
set eof f to 0
write s to f
close access f
end writeFile
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.