FileOpen Procedure

Opens the file specified by sFileName and prepares the file for subsequent reading or writing.

Syntax

[ hFile = ] FileOpen ( sFileName [, lMode] )

The FileOpen procedure syntax has the following parts:

 

Name

Type

Description

hFile

Val AFile

Returned handle to file,  -1 on error

sFileName

Val BString

Name of file to open

lMode

Val enumAFileMode

File mode

Where

enumAFileMode can be one or a combination of of the following values, the combination of the default value constants are marked with an asterisk(*):

 

Name

Value

Description

aFileModeRead

0x00000001 *

Allows Read access to the file

aFileModeWrite

0x00000002 *

Allows Write access to the file

aFileModeShareDelete

0x00000010

File Share Delete. Subsequent open operation will succeed only if delete access is requested.

aFileModeShareRead

0x00000020

File Share Read. Subsequent open operation will succeed only if read access is requested.

aFileModeShareWrite

0x00000040

File Share Write. Subsequent open operation will succeed only if write access is requested.

aFileModeCreateNew

0x00000100

Creates a new file. This function fails if the specified file exists.

aFileModeCreateAlways

0x00000200

Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes.

aFileModeOpenExisting

0x00000400 *

Opens the file. The function fails if the file does not exist.

aFileModeOpenAlways

0x00000800

Opens the file if it exists. If the file does not exist, the function creates the file.

aFileModeTruncateExisting

0x00001000

Opens the file. Once opened, the file is truncated to 0 bytes.

aFileModeAttributeArchive

0x00010000

The file should be archived. It will be marked for backup or removal.

aFileModeAttributeEncrypted

0x00020000

All data in the file is encrypted.

aFileModeAttributeHidden

0x00040000

The file is hidden.

aFileModeAttributeNormal

0x00080000

The file has no other attributes set.

aFileModeAttributeOffline

0x00100000

The file data has been physically moved to offline storage and is not immediately available.

aFileModeAttributeReadOnly

0x00200000

The file is set for read only.

aFileModeAttributeSystem

0x00400000

The file is part of or is used exclusively by the operating system.

aFileModeAttributeTemporary

0x00800000

The file is being used for temporary storage.

aFileModeFlagWriteThrough

0x02000000

Instructs the system to write through any intermediate cache and go directly to disk. The system can still cache write operations, but cannot flush them.

aFileModeFlagNoBuffering

0x04000000

Instructs the system to open the file with no intermediate buffering or caching.

aFileModeFlagDeleteOnClose

0x08000000

Indicates that the operating system is to delete the file immediately after all of its handles have been closed.

Comments

The file pointer is set to the beginning of the file.

One of the following Create/Open mode flags must be set for the function to be successful: aFileModeCreateNew, aFileModeCreateAlways, aFileModeOpenExisting, aFileModeOpenAlways, or aFileModeTruncateExisting.

If the function was successful, it returns the ATEasy file handle. Otherwise, it returns -1. Common causes for errors are: the file does not exist, the given path or filename was not valid, the file is a read-only file, or there are too many open files.

Example

The following example opens a file. If the file can't be opened (for example, it doesn't exist) FileCreate tries to create it.

sFileName="c:\\ATEasy\\data.dat"

hFile = FileOpen(sFileName)

If hFile = -1 Then

print "Unable to Open file: ", sFileName, " Attempting to Create"

hFile = FileCreate(sFileName)

if hFile = -1 Then

print "Unable to create file: ", sFileName

Endif

Endif

See Also

FileClose, FileCreate, FileRead, FileSeek, FileWrite, GetDir