extension Function

public function extension(fname) result(res)

Determines the extension of a file given its name or path.

Syntax

 l = extension(fname)

Where:

  • fname: Name or path of the file the determine the extension.

It returns the extension of the file including the "dot". Empty path is returned if no extension is found.

Example

The following program gets the extensions of some files

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

Arguments

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

Filename or path to a file.

Return Value character(len=:), ALLOCATABLE

Extension of the file including the "dot". Empty path is returned if no extension is found.


Contents