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

getRelativePath

Gets the relative pathname relative to a directory


Description

Gets the relative pathname relative to a directory.

Usage

## Default S3 method:
getRelativePath(pathname, relativeTo=getwd(), caseSensitive=NULL, ...)

Arguments

pathname

A character string of the pathname to be converted into an relative pathname.

relativeTo

A character string of the reference pathname.

caseSensitive

If TRUE, the comparison is case sensitive, otherwise not. If NULL, it is decided from the relative path.

...

Not used.

Details

In case the two paths are on different file systems, for instance, C:/foo/bar/ and D:/foo/, the method returns pathname as is.

Value

Returns a character string of the relative pathname.

Non-case sensitive comparison

If caseSensitive == NULL, the relative path is used to decide if the comparison should be done in a case-sensitive mode or not. The current check is if it is a Windows path or not, that is, if the relative path starts with a device letter, then the comparison is non-case sensitive.

Author(s)

Henrik Bengtsson

See Also

Examples

getRelativePath("foo", "foo")                       # "."
  getRelativePath("foo/bar", "foo")                   # "bar"
  getRelativePath("foo/bar", "foo/bar/yah")           # ".."
  getRelativePath("foo/bar/cool", "foo/bar/yah/sub/") # "../../cool"
  getRelativePath("/tmp/bar/", "/bar/foo/")           # "../../tmp/bar"

  # Windows
  getRelativePath("C:/foo/bar/", "C:/bar/")           # "../foo/bar"
  getRelativePath("C:/foo/bar/", "D:/bar/")           # "C:/foo/bar"

R.utils

Various Programming Utilities

v2.10.1
LGPL (>= 2.1)
Authors
Henrik Bengtsson [aut, cre, cph]
Initial release

We don't support your browser anymore

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