Opens a file.

FOpenEx(cFileName [, nAttributesAndFlags [, nAccessMode [, nShareMode]]])

Parameters

cFileName

The name of the file you want to open.
Can be pathed relatively, absolutely, or with UNC.

nAttributesAndFlags (optional, additive)

Flags how to open the file.

ValueDescription
FILE_FLAG_BACKUP_SEMANTICSThe file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges.
You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead of a file handle. For more information, see the Remarks section.
FILE_FLAG_DELETE_ON_CLOSEThe file is to be deleted immediately after all of its handles are closed, which includes the specified handle and any other open or duplicated handles.
If there are existing open handles to a file, the call fails unless they were all opened with the FILE_SHARE_DELETE share mode.
Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE share mode is specified.
FILE_FLAG_NO_BUFFERINGThe file or device is being opened with no system caching for data reads and writes.
This flag does not affect hard disk caching or memory mapped files.
There are strict requirements for successfully working with files opened with CreateFile using the FILE_FLAG_NO_BUFFERING flag.
FILE_FLAG_OPEN_NO_RECALLThe file data is requested, but it should continue to be located in remote storage. It should not be transported back to local storage. This flag is for use by remote storage systems.
FILE_FLAG_POSIX_SEMANTICSAccess will occur according to POSIX rules. This includes allowing multiple files with names, differing only in case, for file systems that support that naming. Use care when using this option, because files created with this flag may not be accessible by applications that are written for MS-DOS or 16-bit Windows.
FILE_FLAG_RANDOM_ACCESSAccess is intended to be random. The system can use this as a hint to optimize file caching.
This flag has no effect if the file system does not support cached I/O and FILE_FLAG_NO_BUFFERING.
FILE_FLAG_SEQUENTIAL_SCANAccess is intended to be sequential from beginning to end. The system can use this as a hint to optimize file caching.
This flag should not be used if read-behind (that is, backwards scans) will be used.
This flag has no effect if the file system does not support cached I/O and FILE_FLAG_NO_BUFFERING.
FILE_FLAG_WRITE_THROUGHWrite operations will not go through any intermediate cache, they will go directly to disk.

Note

For more information on the flags have a look at the CreateFile documentation.

nAccessMode (optional)

default = 0

valid values:
0 - read only
1 - write only
2 - read/write

nSharemode (optional)

default = 0 (no sharing)

One or a combination of the following values.
SharemodeDescription
0Prevents other processes from opening a file or device if they request delete, read, or write access.
FILE_SHARE_READ Enables subsequent open operations on a file or device to request read access.
Otherwise, other processes cannot open the file or device if they request read access.
If this flag is not specified, but the file or device has been opened for read access, the function fails.
FILE_SHARE_WRITEEnables subsequent open operations on a file or device to request write access.
Otherwise, other processes cannot open the file or device if they request write access.
If this flag is not specified, but the file or device has been opened for write access or has a file mapping with write access, the function fails.
FILE_SHARE_DELETEEnables subsequent open operations on a file or device to request delete access.
Otherwise, other processes cannot open the file or device if they request delete access.
If this flag is not specified, but the file or device has been opened for delete access, the function fails.
Note: Delete access allows both delete and rename operations.

Return Value

Returns a handle (integer) to the file. A positive integer indicates the file was opened successfully, while -1 indicates failure.

Example

Copy code
LOCAL nFileHandle
nFileHandle=FOPENEX("c:\temp\audit.log")
? nFileHandle
&& Now you can manipulate that file using nFileHandle as a parameter into the other functions.

See Also

Reference

AFHandlesEx
FChSizeEx
FCloseEx
FCreateEx
FEoFEx
FFlushEx
FGetsEx
FLockFile
FLockFileEx
FPutsEx
FReadEx
FSeekEx
FUnlockFile
FUnlockFileEx
FWriteEx

Used WinApi functions

CreateFile