Eyeon:Script/Reference/Libraries/io/input

From VFXPedia

Jump to: navigation, search

Contents

IO : io.input

Arguments

io.close( [file_handle] )

  • file (optional, file handle or file name)

A file handle object or the path to a file on disk.

Returns

This function does not return a value.

Remarks

The io.input() function sets the default input file. The default input is the file used by the io class of functions, for example a call to io.read() will read data from the default input file.

If this function is called with a string specifying a path to a file on disk it opens the file names, and sets its file handle to the default input. If this function is called with a file handle object as its argument the file handle is set as the current default input.

If this function is called without any arguments it returns the file handle object for the current default file.

This function does not return an error code, if it fails it simply raises an error, which is likely to halt the script. This behavior means that it is usually wiser to use io.open to set a file handle, and then assign that handle to io.input if you want to open a file.

Requirements

  • eyeonScript 5.0
  • Fusion 5.0

Examples

-- command line script -- accepts an argument which specifies a -- text file and prints that file to screen, -- adding line numbers to the output -- check if the file exists

if fileexists(arg[1]) == nil then

print("Error : The file " .. arg[1] .." does not exist!")
os.exit(10)

end

srcfile = arg[1]

-- try to open the file fh, errorMsg = io.open(srcfile, "r+") if fh == nil then

-- failed to open the file. 
-- print an error and halt
print("Error: Failed to open input file!")
print(errorMsg)
os.exit(20)

end

-- set the file handle to default io.input(fh)

-- read all of the lines at once count = 1 lineval = io.read("*l")

while lineval do

print(count, lineval)
lineval = io.read("*l")
count = count + 1

endio.close(fh)


Tips for input (edit)

EyeonTips:Script/Reference/Libraries/io/input