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

bResult = CFile:Close()

bullet.gif    On success, this method returns true.

bullet.gif    On failure, this method returns false.

Remarks

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 = new_file()

-- 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

CFile class, Open


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.