Junctions and Links

I have a need to create links between directories on a regular basis (e.g. to link between external drives and sync services like OneDrive / Dropbox). As I found this a fairly useful feature I thought I would quickly write up how I use this feature and the structure of the commands.

Prior to going any further, the following information relates to Windows 10 and the NTFS file system. There are three file links which are supported in NTFS which are hard links, junctions and symbolic links.

 

A hard link is essentially a link to a specific file within the same volume, when the original file is changed it is instantly visible to applications that can access it through the hard links.

To create a hard link you can use the mklink command (mklink) which is a built in command of cmd.exe from Windows Vista and later.

The command format is

mklink /H Link Target

/H specifies that the link being created is a hard link, 
Link is the new symbolic link name, and 
Target is the path that the new link refers to.

To create a hard link from the file (file.txt) at C:\temp 
and put this in C:\ you would use the command below;
mklink /H "C:\files.txt" "C:\temp\file.txt"

 

A Directory Junction is different from a hard link in that it references directories rather than individual files, and these directories can be on different local volumes of the same computer. It is Directory Junctions that I use in my case (since I would like to mirror whole folders).

To create a hard link you can use the mklink command (mklink) which is a built in command of cmd.exe from Windows Vista and later.

The command format is

mklink /J Link Target

/J specifies that the link being created is a directory junction, 
Link is the new symbolic link name, and 
Target is the path that the new link refers to.

To create a hard link from the file (file.txt) at C:\temp 
and put this in C:\ you would use the command below;
mklink /J "C:\Newly Created Folder" "C:\Users\Original Folder"

As the directory junction uses reparsepoint, to remove it you can use the commands below.

 

To remove a Directory Junction;

When you are ready to remove the link, you can use the tool fsutil;

fsutil reparsepoint delete link.mp3

This tool allows you to remove the directory junction points but retain the file or directory. It should be noted that it will leave the folder but contents of the junction will only exist in the initial directory.

 

My Workflow;

I have a slightly unusual workflow, I have some files which I have stored in my documents but I want these mirrored to OneDrive (Personal) and Dropbox, to achieve this I have created two directory links

MKLINK /J “C:\Users\USERNAME\OneDrive\Documents\Work in Progress” “C:\Users\USERNAME\Documents\Work in Progress”

MKLINK /J “C:\Users\USERNAME\DropBox\Documents\Work in Progress” “C:\Users\USERNAME\Documents\Work in Progress”

 

Issues;

It should be noted that to create hard links, or directory junctions you need to have administrator privileges. In addition, there are some restrictions around files which can be linked.

 

Tips:

There are a range of other tools, but one of the most recommended is the Link Shell Extension which creates a right click menu. This can be downloaded at https://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html

Prev ON1 360°
Next Topaz DeNoise AI (V2.2.1)

Comments are closed.

Right click has been disabled on this site.