File System

API Folder Location : C:\Users\"UserName"\Documents\My Games\

Filesystem API that allows scripts to read, write, and manage files only inside the main scripting directory.

Scripts cannot access, modify, create, or query files outside this directory. All paths must be relative and are automatically sandboxed for safety.


Overview

The filesystem API provides the following capabilities:

  • Create files

  • Create directories

  • Read files

  • Check if a file exists

  • List files or directories

  • Delete files

  • Delete directories

All functions operate only on paths relative to the script directory.


Path Rules

To ensure safety and consistency:

✔ Paths must be relative

Absolute paths such as:

are not allowed.

✔ Parent-directory traversal is not allowed

Paths cannot contain:

✔ Scripts cannot escape the main scripting directory

Every operation is automatically constrained to the script directory.


Global Functions

All filesystem functions are available as global Lua functions.


create_file(path, [data]) → boolean

Creates or overwrites a file.

Example:


create_directory(path) → boolean

Creates a directory (non-recursive).

Example:


read_file(path) → boolean, string

Reads a file and returns (success, contents).

Example:


does_file_exist(path) → boolean

Checks if a file exists.

Example:


query_directory(path, include_dirs?, include_files?, extensions_table?) → boolean, table

Lists the contents of a directory.

Parameters:

Name
Type
Default
Description

path

string

required

Directory to list

include_dirs

boolean

true

Include subdirectories

include_files

boolean

true

Include files

extensions_table

table

nil

Filter by extensions, e.g. { ".txt" }

Example:

Filter example:


delete_file(path) → boolean

Deletes a file.

Example:


delete_directory(path) → boolean

Deletes a directory (may require the directory to be empty).

Example:


Example Test Script

A simple script to confirm everything is working:

Last updated