Series 2600B System SourceMeter® instrument Reference Manual Section 9: TSP command reference
2600BS-901-01 Rev. F/August 2021 9-95
local fileName = "/usb1/myfile.txt"
if fs.is_file(fileName) then
os.remove(fileName)
print("Removing file")
else
print("Nothing removed")
end
print("\n*** fileVar:close")
do
myfile, myfile_err, myfile_errnum = io.open(fileName, "w")
myfile:write("Line 1")
myfile:close()
end
myfile, myfile_err, myfile_errnum = io.open(fileName, "r")
myfile:close()
os.remove(fileName)
Opens file myfile.txt for writing. If no errors were found while opening, writes Removing file and closes
the file.
Also see
fileVar:flush() (on page 9-95)
fileVar:read() (on page 9-96)
fileVar:seek() (on page 9-98)
fileVar:write() (on page 9-99)
io.close() (on page 9-117)
io.open() (on page 9-119)
fileVar:flush()
This function writes buffered data to a file.
The file descriptor variable to flush
Details
The fileVar:write() or io.write() functions buffer data, which may not be written immediately
to the USB flash drive. Use fileVar:flush() to flush this data. Using this function removes the
need to close a file after writing to it, allowing the file to be left open to write more data. Data may be
lost if the file is not closed or flushed before a script ends.
If there is going to be a time delay before more data is written to a file, and you want to keep the file
open, flush the file after you write to it to prevent loss of data.