exists Function

public function exists(fname) result(res)

Checks if a file or directory exists.

Syntax

 l = exists(fname)

Where:

  • fname: Name of the file to be checked for existence.

It returns True if the file exists and False otherwhise.

Example

The following program check if file1 exists:

 PROGRAM existsExample
    USE FU_Files, ONLY: exists
    IMPLICIT NONE
    CHARACTER(LEN=:), ALLOCATABLE :: path
    path='file1'
    IF (exists(path)) THEN
       WRITE(*,*) 'File exists'
    ELSE
       WRITE(*,*) 'File does not exist'
    END IF
 END PROGRAM existsExample

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fname

Name of the file to be check for existence.

Return Value logical

True if the file exists. False otherwise.


Contents