Library files
File functions. Allows for basic creating and editing text files.
Functions
| 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()). |
| Reads a file from path. | |
| rename( oldName, newName ) | Renames a file. |
| size( fileName ) | Returns the size of the given file. |
| 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:
SharedParameters:
-
fileName: Name of the file to append to. -
data: String that will be appended to the file.
Return values:
-
(boolean)True if the file was appended, false otherwise. -
(string)Error message if applicable.
-
- files.delete( fileName )
-
Deletes a file
Environment:
SharedParameters:
-
fileName: The name of the file to be deleted.
Return values:
-
(boolean)True if successful, false if error -
(string)Error message if applicable
-
- files.exists( fileName )
-
Checks if a file exists.
Environment:
SharedParameters:
-
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:
SharedReturn value:
(number)The maximum number of files that can be saved. - files.getMaxSize()
-
Returns the maximum file size.
Environment:
SharedReturn 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:
SharedReturn 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:
SharedReturn value:
(tableA 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:
SharedParameters:
-
(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:
SharedParameters:
-
fileName: Name of the file to read.
Return values:
-
(string | nil)Contents, or nil if error. -
(string)Error message if applicable.
-
- files.rename( oldName, newName )
-
Renames a file.
Environment:
SharedParameters:
-
oldName: The name of the existing file to be renamed. -
newName: The new name to give the file.
Return values:
-
(boolean)True if successful, false if error. -
(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:
SharedParameters:
-
(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:
SharedParameters:
-
fileName: Name of the file to write data to. -
data: String data to write.
Return values:
-
(boolean)True if OK, false if error. -
(string)Error message if applicable.
-