📁 File
A File represents an entry to a system file.
It is not possible to open files from outside the server folder. All path must be relative to the Server's executable folder. All files are opened as binary file by default.
🎒 Examples
local configuration_file = File("my_awesome_configuration.json")
local configuration_file_json = JSON.parse(configuration_file:Read(configuration_file:Size()))
🛠 Constructors
Default Constructor
local my_file = File(file_path, truncate?)
Type | Name | Default | Description |
---|---|---|---|
string | file_path | If on Server, this is the Path relative to server executable. Otherwise if on Client, this is the Path relative to Client's 'Packages/.transient/' folder | |
boolean | truncate | false | Whether or not to clear the file upon opening it |
🗿 Static Functions
Returns | Name | Description | |
---|---|---|---|
![]() | boolean | CreateDirectory | Creates a Directory (for every folder passed) |
![]() | boolean | Exists | Verifies if a entry exists in the file system |
![]() | table of string | GetDirectories | Gets a list of all directories given a path |
![]() | table of string | GetFiles | Gets a list of all files in a directory |
![]() | boolean | IsDirectory | Checks if a path is a directory |
![]() | boolean | IsRegularFile | Checks if a path is a file |
![]() | integer | Remove | Deletes a folder or file |
![]() | integer | Time | Returns when a file was last modified in Unix time |

CreateDirectory
Creates a Directory (for every folder passed)
— Returns boolean (if succeeded).
local ret = File.CreateDirectory(path)
Type | Parameter | Default | Description |
---|---|---|---|
string | path | Path to folder |

Exists
Verifies if a entry exists in the file system
— Returns boolean (if exists).
local ret = File.Exists(path)
Type | Parameter | Default | Description |
---|---|---|---|
string | path | Path to file or folder |

GetDirectories
Gets a list of all directories given a path, optionally with filters
— Returns table of string (List of directories).
local ret = File.GetDirectories(path_filter?)
Type | Parameter | Default | Description |
---|---|---|---|
string | path_filter? |
| Path filter |

GetFiles
Gets a list of all files in a directory, optionally with filters
— Returns table of string (List of files).
local ret = File.GetFiles(path_filter?, extension_filter?)
Type | Parameter | Default | Description |
---|---|---|---|
string or table | path_filter? |
| Path filter |
string | extension_filter? |
| E.g.: .lua |

IsDirectory
Checks if a path is a directory
— Returns boolean (if is a directory).
local ret = File.IsDirectory(path)
Type | Parameter | Default | Description |
---|---|---|---|
string | path | Path to folder |

IsRegularFile
Checks if a path is a file
— Returns boolean (if is a regular file).
local ret = File.IsRegularFile(path)
Type | Parameter | Default | Description |
---|---|---|---|
string | path | Path to file |

Remove
Deletes a folder or file
— Returns integer (amount of files deleted).
local ret = File.Remove(path)
Type | Parameter | Default | Description |
---|---|---|---|
string | path | Path to file or folder |

Time
Returns when a file was last modified in Unix time
— Returns integer (the last update time in unix time).
local ret = File.Time(path)
Type | Parameter | Default | Description |
---|---|---|---|
string | path | Path to file |
🦠 Functions
Returns | Name | Description | |
---|---|---|---|
![]() | Close | Closes the file and destroys the entity | |
![]() | Flush | Flushes content to the file | |
![]() | boolean | HasFailed | Checks if the last operation has Failed |
![]() | boolean | IsBad | Checks if the file status is Bad |
![]() | boolean | IsEOF | Checks if the file status is End of File |
![]() | boolean | IsGood | Checks if the file status is Good |
![]() | string | Read | Reads characters from the File and returns it. Also moves the file pointer to the latest read position. Pass 0 to read the whole file |
![]() | ReadAsync | Reads characters from the File asynchronously. | |
![]() | table | ReadJSON | Reads the whole file as a JSON and returns it. |
![]() | ReadJSONAsync | Reads the whole file as a JSON and returns it asynchronously. | |
![]() | string | ReadLine | Reads and returns the next file line |
![]() | Seek | Sets the file pointer to a specific position | |
![]() | integer | Size | Returns the size of the file |
![]() | Skip | Skips n (amount) positions from the current file pointer position | |
![]() | integer | Tell | Returns the current file pointer position |
![]() | Write | Writes the Data at the current position of the file |

Close
Closes the file and destroys the entity
my_file:Close()

Flush
Flushes content to the file
my_file:Flush()

HasFailed
Checks if the last operation has Failed
— Returns boolean (if last operation failed).
local ret = my_file:HasFailed()

IsBad
Checks if the file status is Bad
— Returns boolean (if status is Bad).
local ret = my_file:IsBad()

IsEOF
Checks if the file status is End of File
— Returns boolean (if is EOF).
local ret = my_file:IsEOF()

IsGood
Checks if the file status is Good
— Returns boolean (if status is Good).
local ret = my_file:IsGood()

Read
Reads characters from the File and returns it. Also moves the file pointer to the latest read position. Pass 0 to read the whole file
— Returns string (file data).
local ret = my_file:Read(length?)
Type | Parameter | Default | Description |
---|---|---|---|
integer | length? | 0 | Length to be read from file |

ReadAsync
Reads characters from the File asynchronously.
my_file:ReadAsync(length, callback)
Type | Parameter | Default | Description |
---|---|---|---|
integer | length | Length to be read from file | |
function | callback | Callback with this format |

ReadJSON
Reads the whole file as a JSON and returns it.
— Returns table (parsed table).
local ret = my_file:ReadJSON()

ReadJSONAsync
Reads the whole file as a JSON and returns it asynchronously.
my_file:ReadJSONAsync(callback)
Type | Parameter | Default | Description |
---|---|---|---|
function | callback | Callback with the file read with this format |

ReadLine
Reads and returns the next file line
— Returns string (file line data).
local ret = my_file:ReadLine()

Seek
Sets the file pointer to a specific position
my_file:Seek(position)
Type | Parameter | Default | Description |
---|---|---|---|
integer | position | Position to offset the file pointer |

Size
Returns the size of the file
— Returns integer (file size).
local ret = my_file:Size()

Skip
Skips n (amount) positions from the current file pointer position
my_file:Skip(amount)
Type | Parameter | Default | Description |
---|---|---|---|
integer | amount | Amount to offset the file pointer |

Tell
Returns the current file pointer position
— Returns integer (current file pointer position).
local ret = my_file:Tell()

Write
Writes the Data at the current position of the file
my_file:Write(data)
Type | Parameter | Default | Description |
---|---|---|---|
string | data | Data to write to the file |