• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Line count of a referenced text file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 14:50:23 -0500

> Date: Tue, 13 Nov 2001 11:53:41 -0400
> Subject: Re: Line count of a referenced text file?
> From: Matthew Broms <email@hidden>

> ... After all, EOF is nothing more than a
> count of the characters, so why not a count of delimiters to get a
> line/paragraph count?

Well, "get eof" tells you how many "characters" there are, but it
doesn't nessesarily "count" them. I'm not a "real" programmer, but I
assume that the Macintosh system of storing files probably keeps a
file's length as an actual property somewhere, so the OS doesn't have
to "count" each time it accesses the file.

(I sure do love quote-marks...)

> Oh well, would be nice, but it sounds like AS just doesn't offer it and I
> don't want to puppet any outside programs. With everything getting so big
> these days, seems like the text handling capabilities of large files might
> be augmented. Wishful thinking I realize. I'll just do it the slow,
> line-by-line way. Thanks again.

Is something like this really that slow?:

set opened_file to open for access (choose file)

set line_count to 0
repeat
try
read opened_file until return
set line_count to line_count + 1
on error
-- eof
exit repeat
end try
end repeat

close access opened_file

line_count


If the lines are exceptionally short, you might try something
like this:

set opened_file to open for access (choose file)


set kBufferSize to 4096
--
-- ... or whatever is good for you, up to your script's memory.


set line_count to 0

-- Of course, it depends on what you consider a line to be.
-- Under earlier versions, I could simple say "count of
-- paragraphs...", but now I have to use the tids to get
-- exactly what I'm after, (in this case, I am assuming a
-- carrage return).
--
set text item delimiters to {return}

repeat
try
read opened_file for kBufferSize
set line_count to line_count + (count of text items in result)
- 1
on error
-- eof
exit repeat
end try
end repeat

set text item delimiters to {""}
close access opened_file

line_count




Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden

Hey, check out:
http://www.zavatone.com/


  • Follow-Ups:
    • Re: Line count of a referenced text file?
      • From: Matthew Broms <email@hidden>
  • Prev by Date: Re: color changer
  • Next by Date: Re: Fast Loading & updating of Handler Libraries
  • Previous by thread: Re: Line count of a referenced text file?
  • Next by thread: Re: Line count of a referenced text file?
  • Index(es):
    • Date
    • Thread