Eyeon:Script/Reference/Libraries/io/fh/close
From VFXPedia
< Eyeon:Script | Reference | Libraries | io | fh
Contents |
IO : fh : close
Arguments
fh:close()
Returns
This function returns nil if it fails, and an arbitrary value which is not nil if it succeeds.
Remarks
The fh.close() function closes the file referenced by the file_handle fh, releasing access to the specified 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 -- read all of the lines at once count = 1 lineval = fh:read("*l")
while lineval do
print(count, lineval) lineval =fh:read("*l")
count = count + 1
end fh:close()