Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self | The string. |
||
character(kind=CK,len=*), | intent(in), | optional | :: | sep | Directory separator. |
Base directory name.
Return the base directory name of a string containing a file name.
type(string) :: astring astring = '/bar/foo.tar.bz2' print '(A)', astring%basedir()//'' ! print "/bar"
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(kind=CK,len=:), | public, | allocatable | :: | sep_ | Separator, default value. |
||
integer, | public | :: | pos | Character position. |
elemental function basedir(self, sep)
!---------------------------------------------------------------------------------------------------------------------------------
!< Return the base directory name of a string containing a file name.
!<
!<### Example
!<
!<```fortran
!< type(string) :: astring
!< astring = '/bar/foo.tar.bz2'
!< print '(A)', astring%basedir()//'' ! print "/bar"
!<```
!---------------------------------------------------------------------------------------------------------------------------------
class(string), intent(in) :: self !< The string.
character(kind=CK, len=*), intent(in), optional :: sep !< Directory separator.
type(string) :: basedir !< Base directory name.
character(kind=CK, len=:), allocatable :: sep_ !< Separator, default value.
integer :: pos !< Character position.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (allocated(self%raw)) then
sep_ = UIX_DIR_SEP ; if (present(sep)) sep_ = sep
basedir = self
pos = index(self%raw, sep_, back=.true.)
if (pos>0) basedir%raw = self%raw(1:pos-1)
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction basedir