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).
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.
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
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | fname |
Filename or path to a file. |
Path of the parent directory without final slash.