text import and export

Kevin Altis (starnet!apple!scic.intel.com!kevin)
Wed, 30 Jun 1993 12:42:54 -0800

Here are a couple of scripts you may find useful for importing and
exporting text. The importTextFile allows you to specify the maximum number
of characters you want to import, if you don't supply a filename for either
routine, they'll prompt you.

Kevin Altis
Intel Corporation
SuperComputer Systems Division
Beaverton, Oregon

---

Scott Raney suggests... >If you don't mind taking a bigger memory hit, an even easier way is: >put shell("cat" && fName) into field "whatever"

-- *** text handlers for MetaCard 1.3Ax

-- note this doesn't return errors, just empty if something goes wrong -- reads text until we reach maxSize -- if maxSize < 1 then we read until we run out of memory, OUCH! -- or end of file (eof) whichever comes first -- Example: -- put importtextfile("prague/readtest.text", -1) into cd fld "flounder" function importTextFile fName, maxSize if fName = empty then answer file "Select text file" if the result = empty then put it into fName else return empty end if set cursor to watch open file fName read from file fName for maxSize close file fName return it end importTextFile

on exportTextFile fName, theBuffer if fName = empty then ask file "Save text as:" with "untitled.txt" if the result = empty then put it into fName else exit exportTextFile end if open file fName write theBuffer to file fName close file fName end exportTextFile