Search code examples
rwindowsshortcut-file

Accessing target of a windows shorcut


In linux machines, it is possible to access where a symbolic link is pointing to by using Sys.readlink function in R or readlink from the command line. Reading its documentation, we see that this is not intended for Windows shortcuts.

In Windows I have not been able to find a one liner to give me where the file points to. The closest I got was from this SO question that demonstrates the use of dir. While the output was not perfect I figured with some regex magic I could isolate the file path.

However when I tried system2('dir'), I received the error "dir" not found.

Is there (a better) way for me to access the file path of a Windows shortcut from R and why can't I use dir through a system call in R?


Solution

  • For anyone in the future finding this thread, the answer is fs::link_path() as pointed out by Edward Visel