dirname(3f) - [M_io:PATHNAMES] strip last component from filename (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
See Also
Author
License
function dirname(FILENAME) result (DIRECTORY)
character(len=*),intent(in) :: FILENAME character(len=:),allocatable :: DIRECTORY
Output FILENAME with its last non-slash component and trailing slashes removed. If FILENAME contains no slash or backslash character, outputAssumes leaf separator is a slash or backslash as determined by separator(3f) and that FILENAME does not contain trailing spaces.
FILENAME pathname to remove the last leaf from
DIRECTORY directory name for pathname
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_dirnameSample program executions:
demo_dirname /usr/bin/ -> "/usr" demo_dirname dir1/str dir2/str -> "dir1" followed by "dir2" demo_dirname stdio.h -> "."
dirname(3c), basename(3c), readlink(3c), realpath(3c)
John S. Urban
Public Domain
Nemo Release 3.1 | dirname (3) | February 23, 2025 |