File I/O and management

Low-level file I/O is supported by the following set of functions, and the WRITE and FCLOSE Actions (see Actions section). Other, higher-level file I/O functions such as $file, and Actions such as GETFILE as listed elsewhere in this and the Actions section. (Low-level file I/O in Mbot is implemented by calls to the MS Visual C Runtime DLL which is included with Windows.)

@fopen[$filename,$mode]
Opens a file with the specified name, in the specified mode ("r", "w" or "a" for read, write or append), and returns a file handle that is used by related functions to refer to the file. Use the FCLOSE Action to close the file, the WRITE Action to write to the file (see the Actions section).

@ferror[@handle]
Returns 0 if no error has occurred, or a negative error code.

@eof[@handle]
Returns 1 if the file with the specified handle has reached the end-of-file, otherwise returns 0.

$read[@handle,@length]
Returns the next string, up to the EOL or up to 1024, read from the file with the specified handle. (Uses fgets in MSVCRT.DLL). In version Magsbot 6.4.7, the optional @length argument allows you to specify the string length, which may be greater than 1024.

$readln[@handle]
Like $read, except removes the EOL character. (This is a macro in userdefs.udf.)

@getchar[@handle]
Gets a single character from a file.

<>@putchar[@handle,@ch]
Writes a single character to a file. Returns that character written or -1 if an error occurs.

@isfile[$filename]
Returns 1 if the specified file exists, otherwise returns 0.

@ispath[$filename]
Returns 1 if the specified directory exists, otherwise returns 0.



Associated Actions (see the Actions section):
FCLOSE
WRITE

FDELETE
FRENAME
CREATEDIR
SETDIR
FINDFIRST
FINDNEXT


Back to Functions