Functions for reading, writing, and managing files and directories on the host filesystem.
- FILE_Create
- FILE_Open
- FILE_Close
- FILE_Exists
- FILE_Delete
- FILE_Read
- FILE_ReadLine
- FILE_ReadLines
- FILE_Write
- FILE_WriteLine
- FILE_WriteLines
- FILE_Seek
- FILE_MkDir
- FILE_RmDir
- FILE_ReadDir
Creates a new empty file at the given path.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path of the file to create |
FILE_Create("test.txt");Opens a file and returns a file handle. Use the handle with other FILE_* functions.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path of the file to open |
mode |
string | File mode (e.g. "r", "w", "a", "w+") |
file = FILE_Open("test.txt", "w+");Closes an open file handle.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
FILE_Close(file);Returns true if a file exists at the given path, false otherwise.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path to check |
if (FILE_Exists("test.txt"))
{
// ...
}Deletes the file at the given path.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path of the file to delete |
FILE_Delete("test.txt");Reads the entire file contents and returns it as a string.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
string = FILE_Read(file);Reads and returns the next line from the file.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
line = FILE_ReadLine(file);Reads all lines from the file and returns them as an array of strings.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
lines = FILE_ReadLines(file);
for (i = 0; i < lines.size; i++)
ComPrintLn(lines[i]);Writes a formatted string to the file.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
string |
string | Content or format string to write |
arguments |
any | Optional format arguments |
FILE_Write(file, "hello");
FILE_Write(file, "%d %s", 10, "world");Writes a formatted string followed by a newline to the file.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
string |
string | Content or format string to write |
arguments |
any | Optional format arguments |
FILE_WriteLine(file, "hello");
FILE_WriteLine(file, "%d %s", 10, "world");Writes an array of strings to the file, each on its own line.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
lines |
array | Array of strings to write |
FILE_WriteLines(file, lines);Sets the file buffer read/write position.
| Parameter | Type | Description |
|---|---|---|
file |
handle | An open file handle |
offset |
int | Byte offset from the beginning of the file |
FILE_Seek(file, 0);Creates a directory at the given path.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path of the directory to create |
FILE_MkDir("saves");Deletes the directory at the given path.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path of the directory to delete |
FILE_RmDir("saves");Returns an array of file names found in the given directory.
| Parameter | Type | Description |
|---|---|---|
path |
string | Path of the directory to list |
files = FILE_ReadDir("saves");
for (i = 0; i < files.size; i++)
ComPrintLn(files[i]);