Library files

File functions. Allows for basic creating and editing text files.

Functions

append( fileName, data ) Appends a string to the end of a file.
delete( fileName ) Deletes a file
exists( fileName ) Checks if a file exists.
getMaxNumFiles() Returns the current limit on the number of files saved.
getMaxSize() Returns the maximum file size.
isAvailable() Indicates whether file operations are available or not.
list() Returns a table of all saved files.
modifiedTime( fileName ) Returns the time at which the given file was last modified (as a Unix timestamp in seconds i.e. relative to os.time()).
read( fileName ) Reads a file from path.
rename( oldName, newName ) Renames a file.
size( fileName ) Returns the size of the given file.
write( fileName, data ) Writes to a file, overwriting any existing content.


Functions

files.append( fileName, data )
Appends a string to the end of a file.

Deprecated: in favour of io.open.

Environment:

Shared

Parameters:

  • fileName: Name of the file to append to.
  • data: String that will be appended to the file.

Return values:

  1. (boolean) True if the file was appended, false otherwise.
  2. (string) Error message if applicable.
files.delete( fileName )
Deletes a file

Environment:

Shared

Parameters:

  • fileName: The name of the file to be deleted.

Return values:

  1. (boolean) True if successful, false if error
  2. (string) Error message if applicable
files.exists( fileName )
Checks if a file exists.

Environment:

Shared

Parameters:

  • fileName: The name of the file to check.

Return value:

    (boolean) True if exists, false if not.
files.getMaxNumFiles()
Returns the current limit on the number of files saved.

Environment:

Shared

Return value:

    (number) The maximum number of files that can be saved.
files.getMaxSize()
Returns the maximum file size.

Environment:

Shared

Return value:

    (number) The maximum number of bytes a file can contain.
files.isAvailable()
Indicates whether file operations are available or not. If running on the client, file operations are only available when executing on the chip owner's client.

Environment:

Shared

Return value:

    (boolean) True if file operations are available, false otherwise.
files.list()
Returns a table of all saved files. Can only be used on the server, or on the chip owner's client.

Environment:

Shared

Return value:

    (table) A table containing every file currently saved in the instance owner's script data folder.
files.modifiedTime( fileName )
Returns the time at which the given file was last modified (as a Unix timestamp in seconds i.e. relative to os.time()).

Environment:

Shared

Parameters:

  • (string) fileName: The name of the file to get the last modified time of.
files.read( fileName )
Reads a file from path.

Deprecated: in favour of io.open/io.input.

Environment:

Shared

Parameters:

  • fileName: Name of the file to read.

Return values:

  1. (string | nil) Contents, or nil if error.
  2. (string) Error message if applicable.
files.rename( oldName, newName )
Renames a file.

Environment:

Shared

Parameters:

  • oldName: The name of the existing file to be renamed.
  • newName: The new name to give the file.

Return values:

  1. (boolean) True if successful, false if error.
  2. (string) If the operation failed, an error message explaining the failure.
files.size( fileName )
Returns the size of the given file. Note that non-existent files return a value of 0.

Environment:

Shared

Parameters:

  • (string) fileName: The name of the file to get the size of.
files.write( fileName, data )
Writes to a file, overwriting any existing content.

Deprecated: in favour of io.open/io.output.

Environment:

Shared

Parameters:

  • fileName: Name of the file to write data to.
  • data: String data to write.

Return values:

  1. (boolean) True if OK, false if error.
  2. (string) Error message if applicable.

Valid XHTML 1.0!