file_open_read (STRING* name);
Opens a file for reading.
file_open_write (STRING* name);
Opens a file for writing into. If the file does not exist, it is created; otherwise it's previous content is erased.
file_open_append (STRING* name);
Opens a file for appending additional content at the end. If the file does not exist, it is created.
The functions return a file handle - that is a unique number to identify the opened file. The file handle is used by other functions to access that file.
Parameters:
name - file name with or without path, STRING* or char*.
Returns:
File handle, or 0 if the file could not be opened.
Remarks:
- File handles should be defined as non-savable variables ("_n" at the end) when the file is supposed stay open during a game_load call.
- A path can be given with the file name. Otherwise the file is opened in the work folder. A7.66 If the path begins with "%EXE_DIR%", it's opened from a subfolder of the program folder (like "%EXE_DIR%\\include\\mtlFX.c"). If it begins with "%SAVE_DIR%", the file is opened in the save_dir folder. In versions prior to A7.7, the file was always opened in the save_dir folder, even if "%SAVE_DIR%" was not given. This behavior can be reactivated by setting the compatibility variable to 8 or below.
-
The file must physically exist; file buffers or files in resources can not be opened this way. However, files in resources can be extracted with file_cpy, or directly read with file_load.
Example:
var filehandle_n;
...
filehandle_n = file_open_read("adress.txt"); // opens the file address.txt to read
See also:
file_close, file_var_read, file_str_read, file_chr_read, file_asc_read, file_find
► latest version online