Repositions the pointer in a previously opened file.

syntaxSyntax:
DlxFile.Seek(offset, from)

Parameters

Parameter Description
offset Number of characters to move the pointer.
from Pointer movement mode. Must be one of the following values:
DlxApp.FILESEEK_BEGIN Move the file pointer offset characters forward from the beginning of the file.
DlxApp.FILESEEK_CURRENT Move the file pointer offset characters from the current position in the file.
DlxApp.FILESEEK_END Move the file pointer offset characters from the end of the file. Note that offset must be negative to seek into the existing file; positive values will seek past the end of the file.

Return Value

If the operation ends correctly it returns true otherwise it returns false.

Remarks

The Seek function permits random access to a file's contents by moving the pointer a specified amount, absolutely or relatively.

When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.

Example

  Copy codeCopy code
var filename = "demofile.txt";
// write file
var file = new DlxFile(filename, DlxApp.FILEOPEN_WRITETEXT);
if (file.IsValid())
{
  for (var i = 0; i <= 90; i++)
	file.Write(i.toString() + "° : " + Math.sin(i / 180 * Math.PI) + "\n");
  file.Close();
}
// read file
file = new DlxFile(filename, DlxApp.FILEOPEN_READTEXT);
if (file.IsValid())
{
  DlxApp.Printf("File size: %i characters", file.GetLength());
  file.Seek(file.GetLength() /2, DlxApp.FILESEEK_BEGIN);
  DlxApp.Printf("Position; %i", file.GetPosition());
  while (!file.IsEOF())
    DlxApp.Printf("-: %s", file.ReadLine());
  DlxApp.Printf("Position; %i", file.GetPosition());
  file.Close();
}
else DlxApp.Printf("File not found.");

See also