C Library Functions  - dirname (3)

NAME

dirname(3f) - [M_io:PATHNAMES] strip last component from filename (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
See Also
Author
License

SYNOPSIS

function dirname(FILENAME) result (DIRECTORY)

     character(len=*),intent(in)  :: FILENAME
     character(len=:),allocatable :: DIRECTORY

DESCRIPTION

Output FILENAME with its last non-slash component and trailing slashes removed. If FILENAME contains no slash or backslash character, output

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 remove the last leaf from

RETURNS

DIRECTORY
  directory name for pathname

EXAMPLES

Sample program:

   program demo_dirname
   use M_io, only : dirname
   implicit none
   character(len=:),allocatable :: filename
   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(filename))deallocate(filename)
      allocate(character(len=filename_length) :: filename)
      call get_command_argument (i , value=filename)
      write(*,’(a)’)dirname(filename)
   enddo
   end program demo_dirname

Sample program executions:

     demo_dirname /usr/bin/          -> "/usr"
     demo_dirname dir1/str dir2/str  -> "dir1" followed by "dir2"
     demo_dirname stdio.h            -> "."

SEE ALSO

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

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 dirname (3) July 22, 2023
Generated by manServer 1.08 from c4f88999-5100-4bdc-8e3e-75e65430a364 using man macros.