seek

seek — sets the file position for reading or writing.

Syntax

seek (file, offset, where)
		

Arguments

file

A file pointer to a previously opened file. This may be either a file in the file system, or a string opened for read and write.

offset

An integer specifying the number of characters into the file, starting from where.

where

A starting point, indicated by a number:

    Beginning of the file.

    Current position in the file.

    End of the file.

Returns

t if successful, nil if unsuccessful.

Description

This function lets you specify a position in a file to start reading or writing.

Example

The file "myseekfile" contains the following:

Now is the time for all good men and women
to come to the aid of their world.
Gamma> msk = open("myseekfile.dat", "r",nil);
#<File:"myseekfile.dat">
Gamma> seek(msk, 5, 0);
t
Gamma> read_line(msk);
"s the time for all good men and women"
Gamma> seek(msk, 2, 1);
t
Gamma> read_line(msk);
" come to the aid of their world."
Gamma> seek(msk, -15, 2);
t
Gamma> read_line(msk);
"of their world."
Gamma> seek(msk, -3, 0);
nil
Gamma> 
		

See Also

open, open_string, read, read_char, read_double, read_float, read_line, read_long, read_short, read_until, tell