[UP]


Manual Reference Pages  - basename (3)

NAME

basename(3f) - [M_io] return last component from filename (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
See Also
Author
License

SYNOPSIS

function basename(FILENAME,SUFFIX) result (LEAF)

     character(len=:),allocatable :: FILENAME
     character(len=*),intent(in),optional :: SUFFIX
     character(len=*),intent(in) :: LEAF

DESCRIPTION

Output LEAF of filename with directory paths removed.

Assumes leaf separator is a slash or backslash as determined by separator(3f) and that filename does not contain trailing spaces.

OPTIONS

FILENAME
  pathname to extract the last leaf from
SUFFIX suffix to remove. If not present the rightmost ".string" string is removed. If present the LEAF is returned with any matching suffix removed.

RETURNS

LEAF returned leaf name

EXAMPLES

Sample program:

   program demo_basename
   use M_io, only : basename
   implicit none
   character(len=:),allocatable :: fn
   integer                      :: filename_length
   integer                      :: i
   ! get pathname from command line arguments
   do i = 1, command_argument_count()
      call get_command_argument (i, length=filename_length)
      if(allocated(fn))deallocate(fn)
      allocate(character(len=filename_length) :: fn)
      call get_command_argument (i, value=fn)
      ! leaf with any suffix removed
      ! leaf with suffix retained
      ! with suffix unless it is ".f90"
      write(*,’(*(a,1x))’) basename(fn), basename(fn,’’), basename(fn,’.f90’)
      deallocate(fn)
   enddo
   end program demo_basename

Sample program executions:

    $demo_basename /usr/bin/
    bin bin bin
    $demo_basename dir1/fred.x dir2/.y
    fred fred.x fred.x
    .y .y .y
    $demo_basename stdio.h
    stdio stdio.h stdio.h
    $demo_basename /name.f90
    name name.f90 name

SEE ALSO

basename(3c), basename(3c), readlink(3c), realpath(3c)

AUTHOR

John S. Urban

LICENSE

Public Domain


basename (3) March 11, 2021
Generated by manServer 1.08 from ca8874bf-3bf4-4a3a-9d8a-64598f7047bc using man macros.