Re: Mac or UNIX file
Re: Mac or UNIX file
- Subject: Re: Mac or UNIX file
- From: Malcolm Fitzgerald <email@hidden>
- Date: Wed, 6 Dec 2006 10:38:29 +1100
On 06/12/2006, at 7:52 AM, Chris Swain wrote:
I have a script that reads a very large file into a list, adds data to
each item in the list then saves it.
The problem I have is that sometimes the file has UNIX line endings
other times Mac, and if it is a Mac file I need to save it as a Mac
file and vice versa.
I have written two versions of the script one to deal with each, but I
can't see how I might combine them such that I detect the line endings
and then call the appropriate version, I don't want to spend time
reading in the file incorrectly.
Any thoughts,
Read in enough of the file to be sure that you have several lines, then
test for the existence of CR or LF. Then you can process lines one by
one.
eg.
set {lf, return, f} to {ASCII character 10, ASCII character 13, choose
file}
read f for 999 -- whatever is appropriate
if (result contains lf) then set return to lf
set fRef to open for access f
repeat
try
read fRef until return
on error
exit repeat
end try
end repeat
close access fRef
malcolm
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden