Eyeon:Script/Reference/Libraries/io/open

From VFXPedia

Jump to: navigation, search

Contents

IO : io.open

Arguments

io.open( filename, mode )

  • filename (required, string)

A string specifying the file to be opened.

  • mode (required, string)

The mode in which the file is to be opened.

Returns

A file handle object referring to the current object, or nil and a string describing the error if the function is unable to open the file.

Remarks

The io.open function is used to open a file, and return a file handle object for the open file. The file.open requires a filename argument specifying a path to the file on disk, and a mode argument string that identifies the read/write mode used to access the file.

The mode string can be anyone of the following

"r" -- Read Mode

"w" -- Write Mode

"a" -- Append Mode

"r+" -- Update Mode; All previous data is preserved

"w+" -- Update Mode; All previous data is destroyed


  • "a+"

-- Append Update Mode; All previous data preserved, writing only permitted at the end of the file.

By default io.open will access a file in text mode. To access a file as binary, add a "b" to the end of the mode argument.

Requirements

  • eyeonScript 5.0
  • Fusion 5.0

Examples

-- function -- a basic function which copies the file -- source to a new file named dest -- this is an example function only, -- it does no error checking at all

function copyfile(src_path, dest_path)

src = io.open(src_path,"rb")
dest = io.open(dest_path, "wb")
-- read initial 64k of file
bytes = src:read(65536)
repeat
ret = dest:write(bytes)
bytes = src:read(65536)
until bytes == nil
src:close()
dest:close()
return true

end


Tips for open (edit)

EyeonTips:Script/Reference/Libraries/io/open