Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

common_path

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

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

File System Utility Functions for 'NeuroAnatomy Toolbox'

v0.5.1
GPL-3
Authors
Gregory Jefferis
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.