Files

From SphereWiki
Jump to: navigation, search

Using the FILE object reference, scripts can interact with text files. The following table details the various properties of the file object in SphereServer:


Note: Before the FILE object can be used, the OF_FileCommands flag must be set in Sphere.ini's OptionFlags setting.


Properties and Functions

Here is a list of all file properties and functions. If a function is marked as readable then it can return a value when used as <KEY>. Click on the name for more detailed information such as usage and examples.

Name Read/Write Description
CLOSE W Closes the currently open file.
DELETEFILE file_name W Deletes file_name.
FILEEXIST file_name R Returns 1 if file_name exists.
FILELINES file_name R Returns the total number of lines in file_name.
FILEPATH R Returns the name of the currently open file.
FLUSH W Forces all buffered output to be written to the file,
INUSE R Returns 1 if a file is currently open.
ISEOF R Returns 1 if there are no more lines left to read from the file.
LENGTH R Returns the total length of the currently open file, in bytes.
MODE.APPEND RW Gets or sets whether or not the file will be appended to when opened. Cannot be set after the file has been opened.
MODE.CREATE RW Gets or sets whether or not the file will be created when opened. Cannot be set after the file has been opened.
MODE.READLFLAG RW Gets or sets whether or not the file will be opened for reading from. Cannot be set after the file has been opened.
MODE.WRITEFLAG RW Gets or sets whether or not the file will be opened for writing to. Cannot be set after the file has been opened.
MODE.SETDEFAULT W Sets the mode to the default setting. Cannot be set after the file has been opened.
OPEN file_name R Opens a file, and returns 1 if the attempt was successful, using the set MODE flags.
POSITION R Gets the current position in the currently open file, in bytes.
READBYTE R Reads the next byte from the currently open file.
READCHAR R Reads the next character from the currently open file.
READLINE n R Reads the nth line from the currently open file (1-based). 0 Reads the last line.
SEEK position R Changes the current position in the currently open file to position. Accepts "BEGIN" for the start of the file and "END" for the end of the file. Returns the new position in the file.
WRITE text W Writes text to the currently open file.
WRITECHR ascii_value W Writes a single character to the currently open file.
WRITELINE text W Writes text to the currently open file, with newline character(s) on the end.