# 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, "", sep="");
target <- targets[[kk]];
cat("Target: ", target, "", 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, "", sep="");
# Validate that it points to the correct target
dest <- filePath(pathname, expandLinks="any")
cat("Available target: ", dest, "", sep="");
file.remove(pathname)
stopifnot(tolower(dest) == tolower(target))
}
}
Run the code above in your browser using DataLab