basename
Manipulate File Paths

Description

basename removes all parts of the specified path, up to the last path separator.
dirname returns the part of the specified path up to, but not including, the last path separator. (It returns "." if the path contains no path separator.)

Usage

basename(path)
dirname(path)

Arguments

path a character vector that specifies a path to a file.

Details

These functions always remove the trailing file separators before operating on the path. dirname does not return trailing file separators.
These functions are similar to the command line utilities by the same name in Unix/Linux.
Value
returns a character vector the same length as path, containing either the final filenames (basename) or the path up the final filenames (dirname).
See Also
file.path
Examples
dirname(c("salmon.csv", "/users/bob/data/salmon.csv"))
# [1] "."               "/users/bob/data"

basename(c("/users/bob/data/", "/users/bob/data/salmon.csv")) # [1] "data" "salmon.csv"

Package base version 6.0.0-69
Package Index