ColdC gives the ability to handle files with the following functions:
| execute() | fchmod() | fclose() | feof() |
| fflush() | file() | files() | fmkdir() |
| fopen() | frmdir() | fstat() | fread() |
| fremove() | frename() | fseek() | fwrite() |
When a file is opened it is associated (i.e. bound) with the current object. Therefore, most file functions assume there is a file associated with the current object when used (such as fwrite()). If there is not a file, the error ~file is thrown.
If the driver was compiled with the RESTRICTIVE_FILES option, the driver will restrict where on the filesystem files can be manipulated (usually the ~/game_dir/root directory, with the exception of the function execute(), which will use the ~/game_dir/dbbin directory.
A file is opened using the function fopen(), and is closed using the function fclose(). Reaching the end of a file will not close it. Destroying the object for a file will close the file.
Example of opening, writing to and closing a simple text logfile:
fopen("my_file", ">>");
fwrite("Hello world!");
fclose();
Example of reading an image file (the second element in the stat list is the file size in bytes):
stat = fopen("image.gif", "-");
buffer = fread(stat[2]);
fclose();