User manual
Series 3700 System Switch/Multimeter Reference Manual  Section 9: Files 
3700S-901-01 Rev. C / July 2008  9-5 
loadscript file_io_test 
-- get the current date and time 
date_time = os.date('%c', os.time())  
-- open the three files for writing 
myfile1, myfile1_err, myfile1_errnum = 
io.open('/usb1/myfile_io1', 'w') 
myfile2, myfile2_err, myfile2_errnum = 
io.open('/usb1/myfile_io2', 'w') 
myfile3, myfile3_err, myfile3_errnum = 
io.open('/usb1/myfile_io3', 'w') 
if (io.type(myfile1) == 'file') then 
if (io.type(myfile2) == 'file') then 
if (io.type(myfile3) == 'file') then 
-- make myfile1 the default output file 
io.output(myfile1)  
-- write some data to the default file 
io.write('Using io write to myfile1 to io output\n')  
io.write(date_time)  
io.write('\n')  
-- now write to myfile2 using descriptor rather than 
io write command 
myfile2:write(' file handle to write to 
myfile2\n') 
myfile2:write(' while myfile1 is output file for 
io\n') 
-- make myfile2 the default output file 
io.output(myfile2)  
-- write some data to the default file 
io.write('Using io write to myfile2 to io output\n')  
io.write(date_time)  
io.write('\n')  
-- now write to myfile3 using descriptor rather than 
io write command 
myfile3:write(' file handle to write to 
myfile3\n') 
myfile3:write(' while myfile2 is output file for 
io\n') 
-- make myfile3 the default output file 
io.output(myfile3)  
-- write some data to the default file 
io.write('Using io write to myfile3 to io output\n')  
io.write(date_time)  
io.write('\n')  
-- now write to myfile1 using descriptor rather than 
io write command 
myfile1:write(' file handle to write to 
myfile1\n') 
myfile1:write(' while myfile3 is output file for 
io\n') 
-- use the io close rather than file descriptor 
close command 
io.close(myfile1) 
io.close(myfile2) 
io.close(myfile3) 
else 
print('myfile3 did not open for write') 
print('error string is ' .. myfile3_err) 










