Eyeon:Script/Reference/Libraries/io/close

From VFXPedia

Jump to: navigation, search

Contents

IO : io.close

Arguments

io.close( [file_handle] )

  • file_handle (optional, file handle object)

A handle to a file on disk.

Returns

This function returns nil if it fails, and an arbitrary value which is not nil if it succeeds.

Remarks

The io.close() function closes the file referenced by file_handle, releasing access to the specified file. If file_handle is not provided it closes the default input file, as set by io.input.

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

end

io.close(fh)


Tips for close (edit)

EyeonTips:Script/Reference/Libraries/io/close