SplitPath: Split Path In Drive, Path, Filename

Description Usage Arguments Value Author(s) See Also Examples

View source: R/DescTools.r

Description

Split a full path in its components. This is specifically an issue in Windows and not really interesting for other OSs.

Usage

1
SplitPath(path, last.is.file = NULL)

Arguments

path

a path

last.is.file

logical, determining if the basename should be interpreted as filename or as last directory. If set to NULL (default), the last entry will be interpreted if the last character is either \ or / and as filename else.

Value

A list, containing the following components:

normpath

the normalized path as returned by normalizePath

drive

the drive if the OS is Windows, NA else

dirname

the path without directory and without filename

fullfilename

the filename including extension

filename

the filename without extension

extension

the file extension

Author(s)

Andri Signorell <andri@signorell.net>

See Also

dirname, basename

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run:  # Windows-specific example
path <- "C:/Documents/Projects/Import/eyestudy.dta"
SplitPath(path)

path <- "C:/Documents/Projects/Import/"
SplitPath(path)

path <- "C:/Documents/Projects/Import"
SplitPath(path)  # last entry will be taken as filename
SplitPath(path, last.is.file=FALSE)

## End(Not run)

DescTools documentation built on June 17, 2021, 5:12 p.m.