Fortran Library Reference

access: Check File Permissions or Existence

The function is called by:

INTEGER*4 access

status = access ( name, mode )

name

character

Input 

File name  

mode

character

Input 

Permissions  

Return value 

INTEGER*4

Output 

status=0: OK status>0: Error code

access determines if you can access the file name with the permissions specified by mode. access returns zero if the access specified by mode would be successful. See also gerror(3F) to interpret error codes.

Set mode to one or more of r, w, or x, in any order or combination, where r, w, x have the following meanings:

 r Test for read permission
 w Test for write permission
 x Test for execute permission
 blank Test for existence of the file

Example 1: Test for read/write permission:


    INTEGER*4  access, status
    status = access ( 'taccess.data', 'rw' )
    if ( status .eq. 0 ) write(*,*) "ok"
    if ( status .ne. 0 ) write(*,*) 'cannot read/write', status

Example 2: Test for existence:


    INTEGER*4  access, status
    status = access ( 'taccess.data', ' ' )    ! blank mode
    if ( status .eq. 0 ) write(*,*) "file exists"
    if ( status .ne. 0 ) write(*,*) 'no such file', status