createWindowsShortcut {R.utils}R Documentation

Creates a Microsoft Windows Shortcut (.lnk file)

Description

Creates a Microsoft Windows Shortcut (.lnk file).

Usage

## Default S3 method:
createWindowsShortcut(pathname, target, overwrite=FALSE, ...)

Arguments

pathname The pathname (with file extension *.lnk) of the link file to be created.
target The target file or directory to which the shortcut should point to.
overwrite If TRUE, an existing link file is overwritten, otherwise not.
... Not used.

Value

Returns (invisibly) the pathname.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

References

[1] Create a windows shortcut (.LNK file), SS64.com, http://ss64.com/nt/shortcut.html

See Also

readWindowsShortcut()

Examples

# Create Windows Shortcut links to a directory and a file
targets <- list(
  system.file(package="R.utils"),
  system.file("DESCRIPTION", package="R.utils")
)

for (kk in seq(along=targets)) {
  cat("Link #", kk, "\n", sep="");

  target <- targets[[kk]];
  cat("Target: ", target, "\n", sep="");

  # Name of *.lnk file
  pathname <- sprintf("%s.LNK", tempfile())

  tryCatch({
    # Will only work on Windows systems with support for VB scripting
    createWindowsShortcut(pathname, target=target)
  }, error = function(ex) {})

  # Was it created?
  if (isFile(pathname)) {
    cat("Created link file: ", pathname, "\n", sep="");

    # Validate that it points to the correct target
    dest <- filePath(pathname, expandLinks="any")
    cat("Available target: ", dest, "\n", sep="");

    file.remove(pathname)
    stopifnot(tolower(dest) == tolower(target))
  }
}

[Package R.utils version 1.3.2 Index]