December 6, 2018

Directory Junction vs SYMLINK (Symbolic Link)

In the last post Create a Symbolic Link in Windows, we have seen how to create different Symbolic Links, i.e, Hard Link, Directory Symbolic Link and Directory Junction Link. If you have not read the last post I recommend to have a look, it will help you understand better.

In this post we will see how Symbolic Link and Directory Junction fits in different scenarios. At some extent Symbolic Link and Directory Junctions look similar, but they serve different purpose. Here is a list of some of the differences between a junction and a symbolic link.

  • A junction point is designed to target local directories, but a symbolic link can be used for directories and files.
  • A junction can only be linked to a local volume path. Symbolic links can be used to link both local and remote/network path. For example, a symbolic link can link to the network share e.g. \\officenetwork\shared\some-folder.

In windows explorer, the icons displayed for both Symbolic Link and Directory Junction seems identical and you can't differentiate if the created link is a Symbolic Link or a Directory Junction by seeing it. But from the command prompt, you can easily identify the correct type by using DIR command. If you have seen my last post (mentioned above), you may notice that the Directory Junction item will be displayed with <JUNCTION> type in console.

If you try to create a Directory Junction Link to some remote path, it will give you an error message. You have to use Directory Symbolic Link when you need to create a link for remote path. Lets understand this with an example:

Create a Directory Junction Link

In this example, I will create a Directory Symbolic Link to Target remote folder named TestFolder. The directory linked will be created at path C:\SymbolicLink\Network\J_Link.

  • Open the command prompt and go to the path C:\SymbolicLink\Network
  • Run the following command:

       mklink /J "C:\SymbolicLink\Network\J_Link" "\\officenetwork\IT-Developmnet\Idrees\TestFolder"
      

    You will see the error message as follows:

       Local volumes are required to complete the operation.
      
    Directory Junction Link for network path giving error

Create a Directory Symbolic Link

In this example, I will create a Directory Symbolic Link to Target remote folder named TestFolder. The directory linked will be created at path C:\SymbolicLink\Network\J_Link.

  • Open the command prompt and go to the path C:\SymbolicLink\Network
  • Run the following command:

       mklink /D "C:\SymbolicLink\Network\D_Link" "\\officenetwork\IT-Developmnet\Idrees\TestFolder"
      

    You will see the success message as follows:

       symbolic link created for C:\SymbolicLink\Network\D_Link <<===>> \\officenetwork\IT-Developmnet\Idrees\TestFolder
      
    Directory Symbolic Link for network path

    If you run the DIR command at C:\SymbolicLink\Network, you will see that the newly created directory link will be displayed as <SYMLINKD>.

    Directory Symbolic Link for network path - in command prompt

I hope you find this post helpful. I welcome your suggestions or feedback in the comments section below.

1 comment:

  1. Awesome post! Of everything I found on the internet yours was the best resource for setting up a symbolic link. I have a question though. It appears this process results in a local volume path to, essentially, a shortcut. Could we achieve the same result of a symbolic path by using explorer to create a short cut path pointing to the desired network path? Thank you again, Brian

    ReplyDelete