In Windows 10, you can using symbolic links to easily redirect one folder to another location. Symbolic links are widely used in the operating system for its own files and folders. Using symbolic links, you can save your disk space and make your data accessible from various file system locations without physically moving your data.
By symlinking these two folders I got everything working within a few seconds. I created symbolic links named c:\portable and c:\documents without moving a single file or folder. Another interesting thing is that if I move my symbolic links to some other location, for example, to the E: drive, they continue to work and will point to my folders on the D: drive.
Here is how symbolic links can be created.
For symbolic link management, Windows offers you many ways.
The most famous tool is mklink. It has the following syntax (mklink /?):
MKLINK [[/D] | [/H] | [/J]] Link Target
/D - Creates a directory symbolic link. Default is a file symbolic link.
/H - Creates a hard link instead of a symbolic link.
/J - Creates a Directory Junction.
Link - Specifies the new symbolic link name.
Target - Specifies the path (relative or absolute) that the new link refers to.
Now you may wonder what is the difference between a directory symbolic link and a directory junction.
What is the difference between a directory symbolic link and a directory junction
A Directory Junction is an older type of symbolic link, which does not support UNC paths (network paths that begin with \\) and relative paths. Directory junctions are supported in Windows 2000 and later NT-based Windows systems. A directory symbolic link on the other hand also supports UNC and relative paths. However, they require at least Windows Vista. So, in most cases today, the directory symbolic link is the preferred option.
What is the difference between a hard link and a symbolic link
A hard link can be created only for files, not folders. You cannot create a hard link for directories. So, it has more limitations than a Directory Junction and also does not support UNC paths.
How to see if a file or a folder is a symbolic link
Let's create all three types of symbolic links and see how they will be displayed in the operating system.
I will create the folder Winaero on my desktop and the text file Winaero.txt in the same location.
Then, I will create a new symbolic link and a new Directory Junction for the folder and the text file.
The mklink command requires Administrator privileges, so you need to run it from an elevated command prompt.
The following command will create a new directory symbolic link:
mklink /d "c:\users\winaero\desktop\directory symbolic link" "c:\users\winaero\desktop\winaero"
Now, let's create a new directory junction for the Winaero folder, as follows:
mklink /j "c:\users\winaero\desktop\directory junction" "c:\users\winaero\desktop\winaero"
Now, let's create a symbolic link for the text file I created. The command is as follows:
mklink "c:\users\winaero\desktop\file symbolic link.txt" "c:\users\winaero\desktop\winaero.txt"
The situation is different for hard links. Let's create one:
mklink /h "c:\users\winaero\desktop\file hard link.txt" "c:\users\winaero\desktop\winaero.txt"
The only way to ensure that the file is a hard link is to use another console utility, fsutil.
Run it as follows :
fsutil hardlink list "file hard link.txt"
You cannot see if a file is a hard link easily because Explorer out of the box gives no such indication. They behave like regular files in a dir command's output or in File Explorer.
However, hard links are still links to other files. They do not duplicate the target file's content and do not take redundant disk space.
In Windows Vista and later, directory junctions are used to link older file folder paths like C:\Documents and Settings to newer paths like C:\Users. Symbolic links are also used to redirect C:\Users\All Users to C:\ProgramData.
Starting with Windows Vista, hard links are also widely utilized by Windows and its Servicing mechanism. Many system files are hard links to files inside the Windows Component Store folder. If you run the command fsutil hardlink list for explorer.exe, notepad.exe or regedit.exe, you can see this yourself!
The WinSxS folder stores various system files, which are linked via hard links to the files located in the folders C:\Windows, C:\Windows\System32 and other system folders. When operating system updates are installed, the files inside WinSxS are updated and hard linked to system locations again.
That's it. Now you know everything you need to know about symbolic links in Windows 10. Using this information, you can resolve issues with paths when you add a new disk drive in your computer, or move some folder but still need it to be accessible via its previous path. Feel free to leave a comment if you have a question or have something to add.