User manual

Section 9: Files Series 3700 System Switch/Multimeter Reference Manual
9-8 3700S-901-01 Rev. C / July 2008
loadscript filetest
-- script to write 2 lines to a file
-- append 2 lines to the same file
-- read the entire file contents and print them
-- open the file for writing
myfile = io.open('/usb1/myfiletest', 'w')
if io.type(myfile) == 'file' then
myfile:write('This is my first line WRITING\n')
myfile:write('This is my next line WRITING\n')
myfile:close()
-- open the file for appending
myfile = io.open('/usb1/myfiletest', 'a')
if io.type(myfile) == 'file' then
myfile:write('This is my first APPEND line\n')
myfile:write('This is my next APPEND line\n')
myfile:close()
-- open the file for reading
myfile = io.open('/usb1/myfiletest', 'r')
if io.type(myfile) == 'file' then
filecontents = myfile:read('*a')
print('the file contains:')
print()
print(filecontents)
myfile:close()
else
print('The file did not open correctly for reading')
end
else
print('The file did not open correctly for appending')
end
else
print('The file did not open correctly for writing')
end
endscript
After downloading the above script, type filetest() to execute the script.
Here are the output results:
the file contains:
This is my first line WRITING
This is my next line WRITING
This is my first APPEND line
This is my next APPEND line