• 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: Any way to get "file pointer"?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any way to get "file pointer"?


  • Subject: Re: Any way to get "file pointer"?
  • From: Gil Dawson <email@hidden>
  • Date: Fri, 01 Jun 2018 17:18:42 -0700

Thanks, Steve--

Thanks for your suggestion, but the length of the whole file is not quite what
I'm after.

I'm looking for the number of bytes I've read so far.

Here's the gist of my code:

First, we open the file:

set fr to open for access (POSIX file (FilePath))
log "fr =" & fr  --> 1565  (a different integer each time)

Then we read a line at a time:

repeat 3 times
        set aLine to (read fr before linefeed)
        log aLine
end repeat

...and the first three lines are dutifully logged.

It is at this point that I would like to know how many characters we have read,
or, equivalently, the number of the next byte which will be be read if we were
to issue another read command.  I could compute this number by summing the
lengths of the three lines, plus one linefeed apiece, but it seems to me that
that number, which I called the file pointer, just has to be a property of the
file reference.

How to get at it?

log "fr =" & fr

...returns an integer, I'd guess an index into some table, but not any
properties, so far as I can tell.

AppleScript has plenty many ways to inquire about files.  The earliest
AppleScript didn't even mention files.  They were added later, first via
Standard Additions, I think it was.  Today you can ask for all sorts of
information about files via System Events, the Finder, a bunch of osaxen and
maybe even some Unix commands. But I have not yet figgered out how to get the
value of the file pointer out of a file reference.

Please let me know if you do.

--Gil



> On Jun 1, 2018, at 9:54 AM, Steve Mills <email@hidden> wrote:
>
> On Jun 1, 2018, at 10:52, Gil Dawson <email@hidden
> <mailto:email@hidden>> wrote:
>
>> Is there a way to get the current value of the "file pointer" value of an
>> open file?
>>
>> I be reading a text file "before delimiters" without closing and reopening,
>> so each read gets a new line from the file.
>>
>> Then comes a time, I'd like to know the byte number in the file for the next
>> read; i.e., of the first character which the next read will bring.
>
> Since you already have a file reference, just call “get eof fr” where fr is
> your variable for the file reference. It returns the length of the file.
>
> Steve via iPad
>
> _______________________________________________
> 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/archives/applescript-users
>
> This email sent to email@hidden

 _______________________________________________
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/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Any way to get "file pointer"?
      • From: Shane Stanley <email@hidden>
    • Re: Any way to get "file pointer"?
      • From: Christopher Stone <email@hidden>
References: 
 >Any way to get "file pointer"? (From: Gil Dawson <email@hidden>)
 >Re: Any way to get "file pointer"? (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Mysterious OSX Mail scripting problem [solved!]
  • Next by Date: Re: Any way to get "file pointer"?
  • Previous by thread: Re: Any way to get "file pointer"?
  • Next by thread: Re: Any way to get "file pointer"?
  • Index(es):
    • Date
    • Thread