access()

Queries the access mode of the file or directory with the specified path name.

Synopsis

int access(string path, int amode);

Parameters

Parameter Description
path Path name. For example, "scripts/copyText.ctl". You can specify an absolute path or a relative path from the PROJ_PATH directory.
Anmerkung: An empty string "" is interpreted as PROJ_DIR.
amode

Access modes ( for example, F_OK).

Possible modes to query are:

R_OK
Is the file readable?
W_OK
Is the file writeable?
X_OK
Is the file executable?
F_OK
Does the file exist?

Return Value

The function returns 0 if the required access is possible and -1 in the event of an error.

Errors

In the event of missing or incorrect arguments (for example,: Path not transferred as a string).

Description

This function queries the access mode of the file or directory with the specified path name. The required access mode should be specified for the parameter amode. With a concurrent query an OR operation is carried out bit by bit for these values. That means as soon as a possibility is true 0 is returned. The function does not return -1 until all accesses are impossible. With F_OK a query can be performed as to whether the file path exists at all.

Under Windows the function returns -1 if spaces are used in the file name/folder name. If the file name/folder name contains Cyrillic characters and Cyrillic language settings are not configured (e.g. Russian), the function also returns -1.

Einschränkung: Querying X_OK is only meaningful under Linux, under Windows the function always returns 0 (positive).
Wichtig: The function only checks if the stated path exists in case a folder was passed to the function.

The following example checks whether the file config exists in the directory C:/tmp/english/config: If the file exists, 0 is returned. If it does not exist or is written incorrectly, -1 is written to the Log viewer.

main()
{
  int i;
  i=access("C:/tmp/english/config/config", F_OK);
  DebugN(i);
}

The following example checks whether the copyText.ctl in the scripts directory is writable.

main(mapping event)
{
  int i = access("scripts/copyText.ctl", W_OK);
  DebugN("Access to script possible:", i);
}

Assignment

File function

Availability

CTRL