AIT_FileOpen

Description

Opens an existing file, or creates a new file in set access mode.

Format

bool AIT_FileOpen  (
 string strFileName,     // Filename
 integer nAccessMode,    // Access mode
 integer nOperation,     // How to create
 integer nFileHandle     // File handle
);

Parameters

strFileName (input)

Specify the name of a file you want to create or open.

nAccessMode (input)

Specify mode of access to a file, which must be one or combination of the following values.

ValueDescription
GENERIC_READSpecify access to a file to be read. You can read data from the file and move the file pointer. To set mode of reading/writing access, specify the mode in combination with GENERIC_WRITE.
GENERIC_WRITESpecify access to a file to be programmed. You can program the file with data, and move the file pointer. To set mode of reading/writing access, specify the mode in combination with GENERIC_READ.

nOperation (input)

Specify how to handle a file when it exists or does not exist. You have to set one of the following values.

ValueDescription
CREATE_NEWCreates a file. If a specified file already exists, the function will not be executed successfully.
CREATE_ALWAYSCreates a new file. If a specified file already exists, the function overwrites the file.
OPEN_EXISTINGOpens a file. If a specified file does not exist, the function will not be executed successfully.
OPEN_ALWAYSOpens a specified file if it exists. If a specified file does not exist, it is created.
TRUNCATE_EXISTINGOpens a file. The opened file is arranged for the 0-byte size. You have to specify at least GENERIC_WRITE access in a calling process to open a file. If no file exists, the function will not be executed successfully.

nFileHandle (output)

Specify a variable for receiving a file handle. When the function returns, the variable stores the file handle.

Return values

The return value is true if the function was executed normally, and false if not. If the function has returned false, you can use AIT_GetLastError to acquire an extended error code. The following gives the error codes that AIT_GetLastError might return:

Extended error numberError code
2ERROR_FILE_NOT_FOUND
3ERROR_PATH_NOT_FOUND
4ERROR_TOO_MANY_OPEN_FILES
5ERROR_ACCESS_DENIED
6ERROR_INVALID_HANDLE
8ERROR_NOT_ENOUGH_MEMORY
14ERROR_OUTOFMEMORY
15ERROR_INVALID_DRIVE
18ERROR_NO_MORE_FILES
19ERROR_WRITE_PROTECT
21ERROR_NOT_READY
32ERROR_SHARING_VIOLATION
33ERROR_LOCK_VIOLATION
53ERROR_BAD_NETPATH
80ERROR_FILE_EXISTS
82ERROR_CANNOT_MAKE
87ERROR_INVALID_PARAMETER
112ERROR_DISK_FULL
123ERROR_INVALID_NAME
148ERROR_PATH_BUSY
161ERROR_BAD_PATHNAME
183ERROR_ALREADY_EXISTS
206ERROR_FILENAME_EXCED_RANGE
1005ERROR_UNRECOGNIZED_VOLUME
1210ERROR_INVALID_COMPUTERNAME
1214ERROR_INVALID_NETNAME
1231ERROR_NETWORK_UNREACHABLE
1392ERROR_FILE_CORRUPT

Note

Use the AIT_FileClose function to close a file handle returned by AIT_OpenFile.