HyperTalk Reference
Home » HyperTalk Reference » Commands

Note: This is a work in progress and will be formatting errors. Read more about the project on the home page.


read from file fileName [at [-] ¬
integer] {for posInteger |until char}
The read command reads data from a file. (You must have already opened the file with the open file command.) Read places the data into the local variable it.

Reading of a newly opened file starts from the beginning of the file, or optionally at character integer. If you use the form at -integer, reading starts at integer characters from the end of

the file. Subsequent reads continue from the last point read.

continues until it has read the specified number of characters or it reaches the named ASCII character (which can be specified as a constant: colon, comma, end, eof, formfeed, quote, return, space, or tab).

All characters count as data, including return characters at the end of lines, spaces, and tab characters.


read from file "Data" until Z -- read until first Z  
read from file "Data" until tab  
read from file "Data" until return -- read one line
read from file "Data" until end -- read until the end of the file
read from file "Data" for 100 -- read 100 bytes
read from file "Data" at 200 for 100 -- read 100 bytes ¬
                starting at the 200th character in the file
read from file "Data" at -200 for 100 -- read 100 bytes ¬
                starting at the 200th character from the end of the file
read from file "My Data"
-- This function asks for the name of a text file and reads it.
-- You might use it as follows: 

-- put readFile() into myInfo

-- Note that variables can hold unlimited amounts of information
-- while fields can only hold 30k.

function readFile
  answer file "Read what text file?" of type text
  if (it is empty) or (it is "Cancel") then return empty
  put it into theFileName
  open file theFileName
  repeat forever
    read from file theFileName for 16384
    if it is empty then exit repeat
    put it after theData
  end repeat
  close file theFileName
  return theData
end readFile


An expression that evaluates to a text string that is also a valid Macintosh filename.

For example:

"my stack"
"HD20:Wally's Stacks:my stack"
"my file alias"

An expression that evaluates to a positive or negative integer or to zero. For example:

18 - 100
-(3 * sum(1,3,4,5)) + 39
In AppleScript, integer is a value class.

An expression that evaluates to a positive integer.

For example:
67 mod 13
the number of bg fields
the number of backgrounds
the number of cards div 2
See also: background, bkgnd, button, card, chunk, field, menu, and menuItem

An expression that yields a single character.

For example:


Related Topics

« put | HyperTalk Reference | reply »

Version 0.7b1 (March 24, 2022)

Made with Macintosh

Switch to Modern View