Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
File.seek
Move the file pointer to a specified position.
seek(offset, whence)Examples
Read characters in reverse order.
javascript
function main() {
let str = "Hello FMZ!"
let file = os.open("data.txt", "w+")
file.write(str)
// If i > str.length, seek() throws an exception (invalid argument)
for (let i = 1; i <= str.length; i++) {
file.seek(-i, 2)
let data = file.read(1)
Log("i:", i, ", data:", data)
}
file.close()
}Returns
| Type | Description |
number | Returns the new file pointer position. |
Arguments
| Name | Type | Required | Description |
offset | number | Yes | Offset (in bytes). |
whence | number | Yes | Reference position: 0=beginning of file, 1=current position, 2=end of file. |
See Also
Remarks
Used to position the file pointer, the offset parameter can be negative (indicating backward movement).