Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ACCESS Function

Portability Function: Determines if a file exists and how it can be accessed.

Module

USE IFPORT

result = ACCESS(name,mode)

name

(Input) Character*(*). Name of the file whose accessibility is to be determined.

mode

(Input) Character*(*). Modes of accessibility to check for. Must be a character string of length one or greater containing only the characters "r", "w", "x", or "" (a blank). These characters are interpreted as follows.

Character

Meaning

r

Tests for read permission

w

Tests for write permission

x

Tests for execute permission. On Windows* systems, the extension of name must be .COM, .EXE, .BAT, .CMD, .PL, .KSH, or .CSH.

(blank)

Tests for existence

The characters within mode can appear in any order or combination. For example, wrx and r are legal forms of mode and represent the same set of inquiries.

Results

The value of the result is INTEGER(4). It is zero if all inquiries specified by mode are true. If either argument is invalid, or if the file cannot be accessed in all of the modes specified, one of the following error codes is returned:

  • EACCES: Access denied; the file's permission setting does not allow the specified access

  • EINVAL: The mode argument is invalid

  • ENOENT: File or path not found

For a list of error codes, see IERRNO.

The name argument can contain either forward or backward slashes for path separators.

On Windows* systems, all files are readable. A test for read permission always returns 0.

Example

use ifport
! checks for read and write permission on the file "DATAFILE.TXT"
J = ACCESS ("DATAFILE.TXT", "rw")
PRINT *, J
! checks whether "DATAFILE.TXT" is executable. It is not, since
! it does not end in .COM, .EXE, .BAT, or .CMD
J = ACCESS ("DATAFILE.TXT","x")
PRINT *, J