| basename {base} | R Documentation |
basename removes all of the path up to and including the last
path separator (if any).
dirname returns the part of the path up to but
excluding the last path separator, or "." if there is no path
separator.
basename(path) dirname(path)
path |
character vector, containing path names. |
For dirname tilde expansion is done: see the description of
path.expand.
Trailing path separators are removed before dissecting the path,
and for dirname any trailing file separators are removed
from the result.
On Windows this will accept either \ or / as the path
separator, but dirname will return a path using /
(except if a network share, when the leading \\ will be
preserved). Only expect these to be able to handle complete
paths, and not for example just a share or a drive.
A character vector of the same length as path. A zero-length
input will give a zero-length output with no error.
If an element of path is NA, so is the result.
These are not wrappers for the POSIX system functions of the same
names: in particular they do not have the special handling of
the path "/" and of returning "." for empty strings in
basename.
basename(file.path("","p1","p2","p3", c("file1", "file2")))
dirname(file.path("","p1","p2","p3","filename"))