Extract directory component from a file path (“.” if none is present)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | path |
Input file path |
Extracted directory path
pure function dirname(path) result(dir) !> Input file path character(len=*), intent(in) :: path !> Extracted directory path character(len=:), allocatable :: dir integer :: isep, last isep = scan(trim(path), "/\", back=.true.) if (isep == 0) then dir = "." return end if last = verify(path(:isep), "/\", back=.true.) if (last == 0) then dir = path(1:1) else if (last == 2 .and. path(2:2) == ":") then dir = path(1:3) else dir = path(1:last) end if end function dirname