Removes file extension from filename while preserving scientific notation and dots in paths.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | filename |
File name |
Returned string with extension removed
pure function stringtool_obj_RemoveExtension(filename) result(val) !> Removes file extension from filename while preserving ! scientific notation and dots in paths. character(len=*), intent(in) :: filename !! File name character(len=:), allocatable :: val !! Returned string with extension removed ! Work variables integer :: last_slash integer :: last_dot logical :: is_extension character(len=:), allocatable :: ext val=trim(adjustl(filename)) ! Find last path separator and last dot last_slash = index(val, '/', back=.true.) last_dot = index(val, '.', back=.true.) ! Default: assume no extension is_extension = .false. if (last_dot.gt.0 .and. last_dot.gt.last_slash) then ! Grab possible file extension ext = val(last_dot+1:len_trim(val)) ! Check whether this is a file extension or scientific notation if (len_trim(ext).gt.0) then if (scan(ext, 'Ee') .ne.1) then is_extension = .true. end if end if end if ! Remove extenstion if (is_extension) then val = val(:last_dot-1) end if return end function stringtool_obj_RemoveExtension