Section 9: TSP command reference Series 2600B System SourceMeter® instrument Reference Manual
9-98 2600BS-901-01 Rev. F/August 2021
fileVar:seek()
This function sets and gets the present position of a file.
Usage
position, errorMsg = fileVar:seek()
position, errorMsg = fileVar:seek("whence")
position, errorMsg = fileVar:seek("whence", offset)
The new file position, measured in bytes from the beginning of the file
A string containing the error message
The file descriptor variable
A string indicating the base against which offset is applied; the default is "cur"
The intended new position, measured in bytes from a base indicated by whence
(default is 0)
Details
The whence parameters may be any of the following:
"set": Beginning of file
"cur": Current position
"end": End of file
If an error is encountered, it is logged to the error queue, and the command returns nil and the
error string.
Example
local fileName = "/usb1/myfile.txt"
if fs.is_file(fileName) then
os.remove(fileName)
print("Removing file")
else
print("Nothing removed")
end
errorqueue.clear()
print("\n*** fileVar:seek")
myfile, myfile_err, myfile_errnum = io.open(fileName, "w")
myfile:write("Line 1")
myfile:close()
do
myfile, myfile_err, myfile_errnum = io.open(fileName, "r")
position = myfile:seek("end", -1)
print(position)
end
myfile:close()
os.remove(fileName)
Get the present position of a file.