Phonebot developer's reference/Object reference/Using the Phonebot file object

From EtherWiki
< Phonebot developer's reference‎ | Object reference
Revision as of 23:08, 18 July 2012 by Sstrader (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Properties

Syntax Access Description
children R Returns array of file objects. Coerces to false if no children exist.
cursor_pos RW The current position of the access cursor
is_eof R Boolean
is_file R Boolean
is_folder R Boolean
name R The name of the file or folder
parent R The path of the parent file or folder. is_folder will be true. Coerces to false if no parent exists (i.e. this is the root).
path R The full path of the file object. May not exist or may not be invalid.
size RW The size of the file in bytes

Methods (file management)

Syntax Description
boolean = copy_to(path) Copy the file or folder to the path. The path must not exist.
boolean = create_file() Create the file. The file must not exist.
boolean = create_folder() Create the folder. The folder must not exist.
boolean = delete() Delete the file or folder.
boolean = move_to(path) Move the file or folder to the path. The path must not exist.

The following table illustrates how the variable value and path parameter value are combined for copy and move calls. The destination will never be deleted. For move calls, the source will be deleted only if it is moved completely.

Variable value Path parameter Description
/a/x.txt /b/y.txt y.txt is a copy of x.txt
/a/x.txt /a/y.txt A move can be considered a rename in this situation.
/a /b/c Any files and folders under "a" will also be created under "c"
/a /b A move can be considered a rename in this situation.

Methods (content management)

Data is returned from reads as an array of bytes. Use data:array.byte_to_string() to convert to a string.

Data passed in for searching or writing must be an array of bytes. Use data:string.to_byte_array() to convert from a string, or create the array using decimal values 0-255.

Syntax Description
data = read(len) Read a len amount of data from the current cursor position
data = read_line() Read from the current cursor position to the next new line. The new line character is not included.
data = read_to(data) Read from the current cursor position to the next section that matches data. The matched data is not included.
pos = write(data) Write a the data at the current cursor position, return the new cursor position.
pos = write_line(data) Write the data at the current cursor position and append a new line, return the new cursor position.