Repositions the pointer in a previously opened file.
Syntax: |
---|
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:
|
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 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.");
|