Did you know that Windows has supported symlinks since Vista? You can create them using the Windows Command Prompt.
Symbolic Links are basically advanced shortcuts that you create on the command line. Once created, Windows treats them just the same as if they were a normal folder.
For example, let's say you have a program that needs its files at C:\MyProgram, but your C: Drive is dangerously low on space and you'd prefer to install that program on another drive, but it throws errors whenever you try to install it there. For the sake of this argument, we're going to pretend that the installer will allow you to install to an existing directory - so that one way you could solve this problem would be to create a folder called D:\Stuff\MyProgram, and then create a symbolic link at C:\MyProgram which points to D:\Stuff\MyProgram. Now, once you've installed the program and launch it, when it tries to access C:\MyProgram, Windows will automatically redirect it to D:\Stuff\MyProgram, and your program will never know the difference!
This trick can be used for all sorts of things - including syncing any folder with programs such as Dropbox, Google Drive, and OneDrive.
There are two types of Symbolic Link - Hard
and Soft
. Soft Symbolic Links work similarly to a Windows Shortcut
. When you open a soft link to a folder, you will be redirected to the folder where the files are stored - which would probably not be suitable in our example above. A hard link, however, makes it appear as though the file or folder actually exists at the location of the symbolic link, and your applications won't know the difference. I find myself using hard links as my default in most situations - but you can make up your own minds as to which you want to use where.
Windows uses slightly different terms here though. Instead of "hard link" and "soft link", Windows uses the terms "hard link" and "symbolic link". According to the Windows documentation, a "symbolic link" is exactly the same as a "soft link", and the mklink
command is what you need to use to create both kinds.
Firstly, open a Command Prompt in Administrator Mode:
- Click on the
Start
button - Scroll down to the
Windows System
folder in the Start Menu - Right-click on the
Command Prompt
shortcut and selectRun as Administrator
By default (without any additional options), the mklink
command will create a Symbolic Link (or "soft link") to a FILE. The command below creates a symbolic ("soft") link at <link>
pointing to <target>
(you know NOT to type the angle brackets, right?):
mklink <link> <target>
To create a symbolic ("soft") link to a target DIRECTORY, use the /D
option:
mklink /D <link> <target>
To create a "hard link" to a FILE, use:
mklink /H <link> <target>
And to create a "hard link" to a DIRECTORY (also known as a "directory junction"), use:
mklink /J <link> <target>
So, for example, if you wanted to create a directory junction ("hard link" to a folder) at C:\LinkToFolder
which points at C:\Users\Username\TargetFolder
, you'd use the following command:
mklink /J C:\LinkToFolder C:\Users\Username\TargetFolder
If any of your paths have spaces in them, just put quotation marks around them:
mklink /J "C:\Link To Folder" "C:\Users\Username\Target Folder"
If you see the error message "You do not have sufficient privilege to perform this operation", it means that you haven't launched the Command Prompt (or whatever it is you've used) as an Administrator before running the command ... (which means you're rushing things and need to slow down a little, because I DEFINITELY told you that in the first step!)
The good news is that Windows Symlinks can be deleted just like any other file or folder from the Command Prompt, Windows Explorer, and any third-party package you might care to use.