Split a File Path

DESCRIPTION:

Split a full path name into individual components, directory or file names.

USAGE:

file.splitpath(dir, fsep=dirSeparator(), platform=getPlatform())

REQUIRED ARGUMENTS:

dir
a character string representing the path of a file or directory.

OPTIONAL ARGUMENTS:

fsep
character string containing the path separator to use to split up the path name. The default value is the separator that is correct for the platform of the currently running S-PLUS.
platform
character string specifying the operating system to assume when deconstructing the path name. By default, this is the platform of the currently running S-PLUS.

VALUE:

A character vector where each element in the vector is a component of the path.

DETAILS:

The character string given by the argument fsep is used to split up a path name into its component directories (subdirectories) and file name. For example, the Unix path name "/dir/subdir/file.ext" will be spilt into this character vector: c("/dir", "subdir", "file.ext").

The function file.path has the opposite purpose of file.splitpath. It combines strings containing path components into a single path name with the appropriate directory separator character(s).

This function is used by dir.create to create a list of the directories when recursively creating directories.

SEE ALSO:

, , .

EXAMPLES:

# find the wavelets PDF file
fpath <- list.files(path = getenv("SHOME"), full.names = T, recursive = T, type
         = "file", pattern = "wavelets.*pdf")
fspath <- file.splitpath(fpath)
# get the file name
fspath[length(fspath)]
# get the directory containing the file
do.call("file.path", as.list(fspath[-length(fspath)]))