FutureBasic Logo

<<    Index    >> FutureBasic 5

open   statement



Syntax:
open "method[fork]",fileID,ref,recLen

Description:
This statement opens a file so that you can read from it and/or write to it. If you specify a method other than "I", the open statement also creates the file if it doesn't already exist.
The parameters are interpreted as follows:

 method
Specify one of the following letters:

IOpen for input (reading) only. The file must already exist. Other processes may read from the file (but not write to it) while it's open with this method.
OOpen for output (writing) only. If the file already exists, all of its current contents will be destroyed. You have exclusive access to the file (no other process can read from it nor write to it) while it's open with the "O" method. Does NOT support the "resource fork" open.
ROpen for "random access." You can either read from or write to the file. The "file mark" (which indicates where the next read or write operation will occur) is placed initially at the beginning of the file. If you write to the file, you only replace those bytes which you're writing; the rest of the file's contents are unaffected. You have exclusive access to the file.
AOpen for "append." This is just like method "R", except the file mark is placed initially at the end of the file. This method is normally used when you want to add data to the end of an existing file.
NOpen for non-exclusive random access. This is just like method "R", except that other processes may read from the file while you have it open. Your process is the only one allowed to write to the file.

 fork
Specify one of the following letters:

DOpen the "data fork." This is the default value.
ROpen the "resource fork." You should only specify this value if you're doing something like copying an entire resource fork from one file to another, or examining the internal structure of the resource fork. You should not use the Open statement when you want to read or write individual resources; in that case, use a Toolbox function such as HOpenResFile instead. Do not use the Open statement to create a new resource fork; use a Toolbox function such as HCreateResFile instead.

 fileID
Specify a number in the range 1 through 255 which is not being used by any other currently open file. You can use this number to identify the open file in statements and functions such as read#, write, eof, lof, etc. The fileID number is associated with the file until you close the file.

 ref
The 'ref' can be either an FSSpec, FSRef or CFURLRef. The FSRef and CFURLRef are opaque references to the file name and location to be opened. The FSSpec contains the filename and location. Appendix A - File Object Specifiers, describes the composition of each 'ref' type. Open syntax uses any of FSSpec, FSRef or CFURLRef and is identical except when using the "O" ( output ) option with an FSRef. Examples are:
open "I", 1, @specAn FSSpec record is used
open "I", 1, @refAn FSRef object is used
open "O", 3, fileName$, @parentFolderRef An FSRef cannot be created for a non-existent file, so a filename and the FSRef of the parent directory must be supplied
open "I", 2, @url A CFURL object is used.
open "A", 5, @ref An FSRef object is used.
open "R", 2, @ref An FSRef object is used.
open "I", 2, @url A CFURL object is used.

 recLen
This value indicates the length of the records in the file; naturally, it's most useful when the file consists of fixed-length records. The value you specify is used when you execute statement and functions such as record, rec, loc and lof. If you omit this parameter, a default value of 256 is used. If the file doesn't consist of fixed-length records, it's often most convenient to set recLen to 1.

See Also:
close; inkey$; input#; print#; read#; read file; read field; write; write file; write field; record; rec; loc; lof; eof; files$