remove_filename Function

public function remove_filename(fname) result(res)

Removes the filename from a path. It is similar to function parent_path but this one does not remove trailing path separators (if any).

Syntax

 l = remove_filename(fname)

Where:

  • fname: Name or path of the file.

It returns the fname value with the filename removed.

Example

The following program removes the filename of some paths.

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

Arguments

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

Filename or path to a file.

Return Value character(len=:), ALLOCATABLE

The fname value with the filename removed.


Contents