common_path: Find common prefix of two or more (normalised) file paths

View source: R/fsutils.r

common_pathR Documentation

Find common prefix of two or more (normalised) file paths

Description

Find common prefix of two or more (normalised) file paths

Usage

common_path(paths, normalise = FALSE, fsep = .Platform$file.sep)

Arguments

paths

Character vector of file paths

normalise

Whether to normalise paths (with normalizePath, default FALSE)

fsep

Optional path separator (defaults to .Platform$file.sep)

Details

Note that for absolute paths, the common prefix will be returned e.g. common_path(c("/a","/b")) is "/"

Note that normalizePath 1) operates according to the conventions of the current runtime platform 2) is called with winslash=.Platform$file.sep which means that normalised paths will eventually end up separated by "\" by default on Windows rather than by "//", which is normalizePath's standard behaviour.

Value

Character vector of common prefix, "" when there is no common prefix, or the original value of paths when fewer than 2 paths were supplied.

See Also

normalizePath

Other path_utils: abs2rel(), split_path()

Examples

common_path(c("/a","/b"))
common_path(c("/a/b/","/a/b"))
common_path(c("/a/b/d","/a/b/c/d"))
common_path(c("/a/b/d","/b/c/d"))
common_path(c("a","b"))
common_path(c("","/a"))
common_path(c("~","~/"))
common_path(c("~/a/b/d","~/a/b/c/d"), normalise = FALSE)
common_path(c("~","~/"), normalise = FALSE)

nat.utils documentation built on June 7, 2023, 6:30 p.m.