file_object - Windower/packages GitHub Wiki

local file = require('file')

local file_object = file.new(path)

File objects are used as proxies to check paths, read from files and write to files.

A file object contains the following functions:



file_object:exists

Checks whether or not the file exists.

Definition

function file_object:exists() : boolean

Parameters

Return

exists boolean

true if the path of the file object exists, false otherwise.



file_object:read

Reads the contents of a file. Errors if the file does not exist or is inaccessible.

Definition

function file_object:read() : string

Parameters

Return

contents string

The full contents of the file as a string.



file_object:write

Writes the provided string to the file. If the file does not exist yet it will be created. If it does exist it will be fully overwritten.

Definition

function file_object:write(content : string)

Parameters

content string

The string to write to the file. May be a binary string, but non-string types will not be converted and will error.

Return

This function does not return any values.



file_object:log

Writes the provided string to the file and appends a new line at the end. If the file does not exist yet it will be created. If it does exist it the new string and the new line will be appended.

Definition

function file_object:log(content : string)

Parameters

content string

The string to write to the file. May be a binary string, but non-string types will not be converted and will error.

Return

This function does not return any values.

⚠️ **GitHub.com Fallback** ⚠️