Re: Line count of a referenced text file?
Re: Line count of a referenced text file?
- Subject: Re: Line count of a referenced text file?
- From: Arthur J Knapp <email@hidden>
- Date: Tue, 13 Nov 2001 15:05:58 -0500
>
Date: Tue, 13 Nov 2001 09:46:36 -0800
>
Subject: Re: Line count of a referenced text file?
>
From: Christopher Nebel <email@hidden>
>
set line_count to 0
>
set fp to open for access the_file
>
repeat
>
try
>
read fp until return
>
set line_count to line_count + 1
>
on error
>
-- probably ran out of lines to read.
>
exit repeat
>
end
>
end
>
close access fp
>
(same as above, but replace the try body with this:)
>
read fp for 4096
>
set line_count to line_count + count_characters(the result, return)
Whoops, I just posted something that looks almost exactly like this.
Someone is going to think I was plagiarizing. ;-)
>
As Paul Berkowitz pointed out, if you know you're counting lines, it's
>
faster to just say "count paragraphs of s".
Again, there was a change at some point regarding line-endings in
AppleScript. If *any* line-ending is OK, then "paragraphs" is OK.
Frequently, I have need to separate the count of carrage returns
from newlines.
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.zavatone.com/