[UP]


Manual Reference Pages  - splitpath (3)

NAME

splitpath(3f) - [M_io] split a Unix pathname into components (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Results
Example
Author
License

SYNOPSIS

subroutine splitpath(path,dir,name,basename,ext)

   integer,parameter :: maxlen=4096
   character(len=maxlen),intent(in)  :: path
   character(len=maxlen),intent(out),optional :: dir
   character(len=maxlen),intent(out),optional :: name
   character(len=maxlen),intent(out),optional :: basename
   character(len=maxlen),intent(out),optional :: ext

DESCRIPTION

splitpath(3f) splits given pathname assuming a forward slash separates filename components and that the right-most period in the last leaf of the pathname is considered the beginning of an extension. If an extension is found it is left present in NAME but removed from BASENAME.

This routine does not check the system for the existence or type of the filename components; it merely parses a string.

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

OPTIONS

path Path to be broken into components. It is assumed
o Forward slashes (/) separate pathname components.
o the name ’.’ means "current directory"
o the name ’..’ means "up one directory"
o a pathname ending in a slash is a directory name
o a slash starting the pathname represents the root directory.
o trailing spaces are insignificant.
Using these rules helps to reduce incorrect parsing, but the routine is only intended for simple parsing of names of the form "[dir/]name[.extension].

RESULTS

dir Path of directories, including the trailing slash.
name Name of file leaf or, if no file is specified in path, name of the lowest directory.
basename
  NAME with any extension removed
ext File name extension, if any, including the leading period (.).
The path parameter can be a complete or partial file specification. The special name "." is assumed to mean the current directory, and the special name ".." is assumed to mean one directory above the current directory.

EXAMPLE

program demo_splitpath

   use m_io, only : splitpath
   implicit none
   integer,parameter :: maxlen=4096
   character(len=maxlen),parameter   :: file(*)=[&
      & ’dirs/name.ext  ’, &
      & ’xx/IO/zz/NN.FF ’, &
      & ’xx/IO/zz/NN    ’, &
      & ’/xx/IO/zz/NN   ’, &
      & ’/xx/IO/zz/     ’, &
      & ’/xx/IO/zz.A/   ’, &
      & ’/xx/IO/zz/.    ’, &
      & ’               ’, &
      & ’./             ’, &
      & ’/              ’, &
      & ’/..            ’, &
      & ’./..           ’, &
      & ’name.          ’, &
      & ’.name          ’, &
      & ’.name.         ’, &
      & ’.              ’, &
      & ’..             ’, &
      & ’...            ’]

character(len=maxlen) :: dir character(len=maxlen) :: name character(len=maxlen) :: basename character(len=maxlen) :: ext integer :: i integer :: longest longest=maxval(len_trim(file)) ! find longest filename

do i=1,size(file) call splitpath(file(i), dir, name, basename, ext) write(*,’(*("| ",a:))’) & & file(i)(:longest), & & dir(:longest), & & name(:longest), & & basename(:longest), & & ext(:longest) enddo

end program demo_splitpath

Output

   | dirs/name.ext | dirs          | name.ext      | name          | .ext
   | xx/IO/zz/NN.FF| xx/IO/zz      | NN.FF         | NN            | .FF
   | xx/IO/zz/NN   | xx/IO/zz      | NN            | NN            |
   | /xx/IO/zz/NN  | /xx/IO/zz     | NN            | NN            |
   | /xx/IO/zz/    | /xx/IO/zz     |               |               |
   | /xx/IO/zz.A/  | /xx/IO/zz.A   |               |               |
   | /xx/IO/zz/.   | /xx/IO/zz/.   |               |               |
   |               | .             |               |               |
   | ./            | .             |               |               |
   | /             | /             |               |               |
   | /..           | /             |               |               |
   | ./..          | ./..          |               |               |
   | name.         |               | name.         | name          | .
   | .name         |               | .name         | .name         |
   | .name.        |               | .name.        | .name         | .
   | .             | .             |               |               |
   | ..            |               |               |               |
   | ...           |               | ...           | ..            | .

AUTHOR

John S. Urban

LICENSE

Public Domain


splitpath (3) March 11, 2021
Generated by manServer 1.08 from 00188ab2-95c6-427e-9a77-a9609fc20537 using man macros.