filePath

0th

Percentile

Construct the path to a file from components and expands Windows Shortcuts along the pathname from root to leaf

Usage
## S3 method for class 'default}(..., fsep=.Platform$file.sep, removeUps=TRUE, expandLinks=c("none", "any", "local", "relative", "network"), mustExist=FALSE, verbose=FALSE)':
filePathundefined

 Construct the path to a file from components and expands Windows Shortcuts along the pathname from root to leaf.  This function is backward compatible with
   file.path() when argument removeUps=FALSE and
   expandLinks="none".

   This function exists on all platforms, not only Windows systems.

 ...{Arguments to be pasted together to a file path and then be
      parsed from the root to the leaf where Windows shortcut files are
      recognized and expanded according to argument which in each
      step.}
   fsep{the path separator to use.}
   removeUps{If TRUE, relative paths, for instance "foo/bar/../"
      are shortend into "foo/", but also "./" are removed from the final
      pathname, if possible.}
   expandLinks{A character string. If "none", Windows
      Shortcut files are ignored.  If "local", the absolute target
      on the local file system is used. If "relative", the relative
      target is used. If "network", the network target is used. If
      "any", the first the local, then the relative and finally the
      network target is searched for.}
   mustExist{If TRUE and if the target does not exist, the original
      pathname, that is, argument pathname is returned. In all other
      cases the target is returned.}
   verbose{If TRUE, extra information is written while reading.}

 Returns a character string.

 
If expandLinks==TRUE, each component, call it parent, in the absolute path is processed from the left to the right as follows: 1. If a "real" directory of name parent exists, it is followed. 2. Otherwise, if Microsoft Windows Shortcut file with name parent.lnk exists, it is read. If its local target exists, that is followed, otherwise its network target is followed. 3. If no valid existing directory was found in (1) or (2), the expanded this far followed by the rest of the pathname is returned quietly. 4. If all of the absolute path was expanded successfully the expanded absolute path is returned.
On speed
{ Internal file.exists() is call while expanding the pathname. This is used to check if the exists a Windows shortcut file named 'foo.lnk' in 'path/foo/bar'. If it does, 'foo.lnk' has to be followed, and in other cases 'foo' is ordinary directory. The file.exists() is unfortunately a bit slow, which is why this function appears slow if called many times. } # Default print(file.path("foo", "bar", "..", "name")) # "foo/bar/../name" # Shorten pathname, if possible print(filePath("foo", "bar", "..", "name")) # "foo/name" print(filePath("foo/bar/../name")) # "foo/name" # Recognize Windows Shortcut files along the path, cf. Unix soft links filename <- system.file("data-ex/HISTORY.LNK", package="R.utils") print(filename) filename <- filePath(filename, expandLinks="relative") print(filename) stopifnot(file.exists(filename)) [object Object] readWindowsShortcut(). file.path(). IO
Aliases
  • filePath.default
  • filePath
Documentation reproduced from package R.utils, version 0.7.9, License: LGPL version 2.1 or newer (the releases)

Community examples

Looks like there are no examples yet.