# R: Manipulate File Paths

basename {base} | R Documentation

## Manipulate File Paths

### Description

`basename` removes all of the path up to 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.

### Usage

    basename(path)
    dirname(path)

### Arguments

`path` | character vector, containing path names.

### Details

For `dirname` tilde expansion is done: see the description of `path.expand`.

Trailing file separators are removed before dissecting the path, and for `dirname` any trailing file separators are removed from the result.

### Value

A character vector of the same length as `path`. A zero-length input will give a zero-length output with no error.

### See Also

`file.path`, `path.expand`.

### Examples

    basename(file.path("","p1","p2","p3", c("file1", "file2")))
    dirname(file.path("","p1","p2","p3","filename"))

[Package base version 2.6.0 Index]