CFile:Open


The Open method opens a file and attaches it to the CFile object. Alternatively, you can use the global new_fileopen function to open a file and create its CFile object in one operation.

Syntax

bResult = CFile:Open( sPath, sAccessMode )

bResult = CFile:Open( sPath )

bullet.gif    sPath is the full path specification of the file.

bullet.gif    sAccessMode is a string specifying the File Access Mode.

bullet.gif    if sAccessMode is not specified, the mode "a+b" is used.

bullet.gif    On success, this method returns true.

bullet.gif    On failure, this method returns false.

Remarks

Usually, the CFile class would not be used to open images that are in formats supported by the CImage class, but it may be used to provide raw access to images.

The file access mode sAccessMode controls the access to the file. Using the appropriate modifiers, the file can be opened in binary mode or text mode for reading, writing, truncating, appending, or creating. See File Access Modes.

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

Example

Suppose a text file exists with name sPath. This script opens it and lists its name it it was successfully opened. The name is listed using, at most, 60 characters:

F = new_file()

-- create a CFile object

sPath = GetFileName()

-- use Open dialog to get a file

bOk = F:Open(sPath,"w+t" )

-- open the file in append/text mode

if not bOk then

-- if not opened, then...

  Exit()

-- leave the script, etc.

end

 

F:Printf("Path: %s\n", F:Path(60))

-- write the path into the file

F:Close()

-- close the file when done

Related Topics

CFile class

File Access Modes

Close

new_fileopen

 


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