previous  next
OpenIFile, OpenOFile
Syntax
OpenIFile(S:STRING):DEVICE
OpenOFile(S:STRING):DEVICE
OpenOFile(S:STRING,'w' or 'W'):DEVICE
Summary
open input or output file
Description
These functions open files for input or output.  'OpenIFile' opens
the file with name S.  Input from that file can then be read with
'Get'.  'OpenOFile' opens the file with name S---creating it if it
does not already exist---for output.  The function 'Print On' is then
used for writing output to the file.  If OpenOFile is used without a
second argument or if the second argument is not 'w' or 'W' then
'Print On' will append output to the file.  Otherwise, any existing
file with the name S will be erased before the output is written.

(Note: one would normally use 'Source' to read CoCoA commands from a file.)

Example

D := OpenOFile('my-test');  -- open 'my-test' for output from CoCoA
Print 'hello world' On D;   -- print string into 'mytest'
Print ' test' On D;  -- append to the file 'mytest'
Close(D);  -- close the file
D := OpenIFile('my-test');  -- open 'my-test' for input to CoCoA
Get(D,3);  -- get the first three characters (in Ascii code)
[104, 101, 108]
-------------------------------
Ascii(It);  -- convert the ascii code into characters
hel
-------------------------------
Close(D);
D := OpenOFile('my-test','w'); -- clear 'my-test'
Print 'goodbye' On D; -- 'mytest' now consists only of the string 'goodbye'
Close(D);
See also: