Skip to main content

Open

Open and Openb (Statement)​

Format​

open file_name
open(file_name)
open open_file_number, file_name
open(open_file_number, file_name)
openb file_name
openb(file_name)
openb open_file_number, file_name
openb(open_file_number, file_name)

Description​

Opens a file for reading and writing. The file_name is specified as a string, and may be an absolute or relative path. If the file number is not specified file number zero (0) will be used.
Openb opens the file in a “binary safe” mode. This type of file open is recommended for files where the Readbyte and Writebyte statements are used for input/output.

Note​

BASIC256 may have up to 8 files open at a single time. The files are numbered from 0 to 7. Opening a file to a number while another is already open to that number will close the open file.

Permissions​

The file being opened is checked. A file in the program's own folder, or below it, opens with no question asked; a file elsewhere on the computer asks the user's permission, and the statement fails with ERROR_PERMISSION if that is refused. The decision is made here and once only -- the statements that then read from or write to the open file are not checked again. A path that came back from OpenFileDialog or SaveFileDialog was chosen by the user and opens without a further question. See File and Folder Permissions.

See Also​

Changedir, Close, Currentdir, Dir, Eof, Exists, Freefile, Kill, mkdir, Open, Openb, OpenFileDialog, OpenSerial, Read, Readbyte, Readline, Reset, SaveFileDialog, Seek, Size, Write, Writebyte, Writeline

History​

0.9.?openb was added to open binary files