Passer au contenu principal
Version: latest - a1.7.0 ⚖️

📁 File

A File represents an entry to a system file.

info

🟦 Authority: This class can only be spawned on Server.

info

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.

Example

local configuration_file = File("my_awesome_configuration.json")

local configuration_file_json = JSON.parse(configuration_file:Read(configuration_file:Size()))

Constructor Parameters

TypeNomDefaultDescription
stringfile_pathPath relative to server executable
booleantruncatefalseWhether or not to clear the file upon opening it

Fonctions statiques

Valeur retournéeNomDescription
numberTimeReturns when a file was last modified in Unix time
booleanCreateDirectoryCreates a Directory (for every folder passed\
numberRemoveDeletes a folder or file
booleanExistsVerifies if a entry exists in the file system
booleanIsDirectoryChecks if a path is a directory
booleanIsRegularFileChecks if a path is a file

Time

Returns when the file was last modified in Unix time

Returns number

File.Time(path)
TypeParameterDescription
stringpathPath to file

CreateDirectory

Creates a directory (for every folder passed)

Returns boolean if succeeded

File.CreateDirectory(path)
TypeParameterDescription
stringpathPath to folder

Remove

Deletes a folder or a file

Returns number

File.Remove(path)
TypeParameterDescription
stringpathPath to file or folder

Exists

Gets if a file or folder exists

Returns boolean

File.Exists(path)
TypeParameterDescription
stringpathPath to file or folder

IsDirectory

Gets if a path is a directory

Returns boolean

File.IsDirectory(path)
TypeParameterDescription
stringpathPath to folder

IsRegularFile

Gets if a path is a file

Returns boolean

File.IsRegularFile(path)
TypeParameterDescription
stringpathPath to file

Functions

Valeur retournéeNomDescription
FermerCloses the file
FlushFlushes content to the file
booleanIsEOFChecks if the file status is End of File
booleanIsBadChecks if the file status is Bad
booleanIsGoodChecks if the file status is Good
booleanHasFailedChecks if the last operation has Failed
stringReadReads characters from the File and returns it. Also moves the file pointer to the latest read position. Pass 0 to read the whole file
stringReadAsyncReads characters from the File asynchronously.
stringReadLineReads and returns the next file line
SeekSets the file pointer to a specific position
numberSizeReturns the size of the file
SkipSkips n (amount) positions from the current file pointer position
numberTellReturns the current file pointer position
WriteWrites the Data at the current position of the file

Fermer

Closes the file

my_file:Close()

Flush

Flushes content to the file

my_file:Flush()

IsEOF

Checks if the file status is End of File

Returns boolean

my_file:IsEOF()

IsBad

Checks if the file status is Bad

Returns boolean

my_file:IsBad()

IsGood

Checks if the file status is Good

Returns boolean

my_file:IsGood()

HasFailed

Checks if the last operation has Failed

Returns boolean

my_file:HasFailed()

Read

Reads n (Length) 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

my_file:Read(length)
TypeParameterDefault ValueDescription
numberlength0Length to be read from file

ReadAsync

Reads n (Length) characters from the File asynchronously. Also moves the file pointer to the latest read position. Pass 0 to read the whole file

my_file:ReadAsync(length, function(content)

end)
TypeParameterDefault ValueDescription
numberlengthLength to be read from file
functioncallbackCallback with the file read

ReadLine

Reads and returns the next file line

Returns string

my_file:ReadLine()

Seek

Sets the file pointer to a specific position

my_file:Seek(position)
TypeParameterDescription
numberpositionPosition to offset the file pointer

Size

Returns the size of the file

Returns number

my_file:Size()

Skip

Skips n (amount) positions from the current file pointer position

my_file:Skip(amount)
TypeParameterDescription
numberamountAmount to offset the file pointer

Tell

Returns the current file pointer position

Returns number

my_file:Tell()

Write

Writes the Data at the current position of the file

my_file:Write(data)
TypeParameterDescription
stringdataWrites the data to the file