DescTools (version 0.99.13)

SplitPath: Split Path In Drive, Path, Filename

Description

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

Usage

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:
  • normpaththe normalized path as returned by normalizePath
  • drivethe drive if the OS is Windows, NA else
  • dirnamethe path without directory and without filename
  • fullfilenamethe filename including extension
  • filenamethe filename without extension
  • extensionthe file extension

See Also

dirname, basename

Examples

Run this code
# 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)

Run the code above in your browser using DataCamp Workspace