CFile:Close


The Close method closes the file and frees operating system connections to it. The CFile object is not deleted and may be used to Open another file.

Syntax

bSuccess = CFile:Close()

    bSuccess is the returned success code. On success it is true, otherwise false.

  

When the script is finished with the file, it should closed using Close or the delete destructor. The delete method sets the CFile object to nil, whereas closing the file leaves the CFile object available for continued use.

Typically you use new to create a CFile object, then use Open and Close to work with it and then clean up afterwards, before eventually calling delete to remove the CFile object.

Example

Suppose a file exists with a full path named sPath. The script below shows the file being opened for reading and writing and then closed:

F = CFile:new()

-- create a CFile object

sAccess = "r+t"

-- access mode: open for reading and writing

bOk = F:Open(sPath,sAccess)

-- open the file

if not bOk then

-- if not opened, then...

  Exit()

-- leave the script, etc.

end

 

  --

-- do some operations...

F:Close()

-- close the file

F:delete()

-- if not opening another file, delete the object.

Related Topics

Open

CFile class