'read myFileRef from 0 before myEOF' only returns 6 chars

Strange problem. This is in OSX 10.3.9

I have a script that creates and later reads a small text file. On several machines it works perfectly.
On one it only returns the first 6 chars of the file!
I’ve checked that eof is returning the correct integer on the ‘bad machine’ and I can’t see any differences between it and the
‘good ones’. Don’t seem to be any problems other than this. I’ve manually replaced the file and I’ve checked it and everything looks
OK and identical to the others. The data in the file (on all machines) is a filepath.

Anyone think of anything clever??

Here’s a snippet of the code:


		set myFileRef to file "FMPBusCardID" in folder "Library" of startup disk as alias
		set myEOF to (get eof of myFileRef) as integer
		set myPrefLocation to read myFileRef from 0 before myEOF

thanks

rhb

What about this variation? (run as-is, out of a “tell app Finder” block):

set theFile to ((path to library folder from local domain as text) & "FMPBusCardID")

set myPrefLocation to read alias theFile

On the “bad” machine, what integer is eof returning? Does that number occur in the file’s text following the first 6 characters, by any chance?

The readbefore syntax specifies the character that the reading stops before, not the byte that it stops before…

…so if eof myFileRef is, say, 22, and the file’s text is, say, “cards:22_may_2005”, then the line

set myPrefLocation to read myFileRef from 0 before myEOF

will return “cards:”, because the integer 22 will be coerced to a “character” (yeah, I know it’s actually 2 characters, but nevertheless that’s how it worked when I tested this possibility).

If you want to read all but the last byte of the file, try

set myPrefLocation to read myFileRef from 0 to myEOF - 1

One other thing: since get eof returns a double integer, there doesn’t seem to be any need to coerce it to an integer.

Another point is that the beginning of a file is ‘1’, not ‘0’. It’s also possible to use the ‘minus’ convention to count from the end, so:

set myPrefLocation to (read myFileRef from 1 to -2)

Hi guys and thank you for your quick responses.
jj of Madrid’s variation:
set theFile to ((path to library folder from local domain as text) & “FMPBusCardID”)
set myPrefLocation to read alias theFile
worked and there didn’t seem to be any of the other factors that others mentioned.

I hadn’t thought of just reading the whole thing! I’ve always done the eof way.

So thanks again to you all

rhb