FileSeek
Repositions file pointer by the specified offset.
Syntax
FileSeek(fileID, offset, type)
Parameters
Parameter |
Type |
Description |
---|---|---|
fileID |
number |
File ID received from |
offset |
number |
Number of bytes to move the file pointer. |
type |
string |
Pointer movement mode. Should be ‘begin’, ‘current’ or ‘end’ |
Return
Returns the new byte offset from the beginning of the file.
Note
FileSeek(file, 0, “end”) returns file size in bytes. FileSeek(file, 0, “current”) returns the current file position.
In Python, you may want to use Python native file.seek() https://www.tutorialspoint.com/python/file_seek.htm .
Examples
Python
import nex
# open binary file in read mode
file = nex.OpenFile("C:\\Data\\binaryfile.dat", "r")
# get file length
fileLength = nex.FileSeek(file, 0, "end")
# move pointer 4 bytes from the beginning of the file
newPosition = nex.FileSeek(file, 4, "begin")
# read short (2-byte signed) value
shortValue = nex.ReadBinary(file, "short")
nex.CloseFile(file)
NexScript
% open binary file in read mode
file = OpenFile("C:\Data\binaryfile.dat", "r")
% get file length
fileLength = FileSeek(file, 0, "end")
% move pointer 4 bytes from the beginning of the file
newPosition = FileSeek(file, 4, "begin")
% read short (2-byte signed) value
shortValue = ReadBinary(file, "short")
CloseFile(file)