parent_path Function

public function parent_path(fname) result(res)

Determines the path to the parent directory given the path to a file. It is similar to function remove_filename but this one removes trailing path separators (if any).

Syntax

 l = parent_path(fname)

Where:

  • fname: Name or path of the file.

It returns the path to the parent directory given the path to a file.

Example

The following program returns the parent paths of some files.

 PROGRAM parent_pathExample
    USE FU_Files, ONLY: parent_path
    IMPLICIT NONE
    CHARACTER(LEN=:), ALLOCATABLE :: path
    path='file1.txt'
    WRITE(*,*) path, ' ', parent_path(path)
    path='./file1.txt'
    WRITE(*,*) path, ' ', parent_path(path)
    path='/tmp/file1.txt'
    WRITE(*,*) path, ' ', parent_path(path)
    path='/tmp/file1.dat'
    WRITE(*,*) path, ' ', parent_path(path)
    path='/tmp/file1'
    WRITE(*,*) path, ' ', parent_path(path)
 END PROGRAM parent_pathExample

Arguments

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

Filename or path to a file.

Return Value character(len=:), ALLOCATABLE

Path of the parent directory without final slash.


Contents