What is a directory junction?
A directory junction is an alias of one folder to another.
Put another way, a directory junction allows you seamlessly access the contents of a folder from another directory, with a different path.
For example, let’s say that you have folder “C:\Users\Username\Documents\Media\All Movies” on your computer. However, you find that directory too long to type when working with it from the command line. You dream of entering a shorter path — such as “C:\Movies” — but you don’t want to copy the files to a new location.
To solve the problem, you would create a directory junction mapping “C:\Movies” to “C:\Users\Username\Documents\Media\All Movies”. After doing that, all your movies will be accessible from “C:\Movies” too. For all practical purposes, “C:\Movies” becomes a synonym for the longer path.
Directory junctions can be created with the with the mklink command. For example, this command creates the alias for the scenario above:
mklink /j "C:\Movies" "C:\Users\Username\Documents\Media\All Movies"
Why use a directory junction with OneDrive?
A directory junction provides convenience and flexibility when designing your cloud synchronization strategy. In theory, by allowing you to place any arbitrary folder inside your OneDrive folder, you can extend the scope of your OneDrive backup without having to duplicate large folders and files.
Let’s illustrate with a practical example.
Say you’ve installed OneDrive to synchronize your OneDrive folder (“C:\OneDrive”) with the cloud. Everything is working well.
However, you also want OneDrive to backup “C:\Shared\CustomerSuccess\Templates” — a shared folder with important company files. How do we instruct OneDrive to sync that folder as well?
Well, this is where folder linking comes in. You can create a directory junction in your OneDrive folder that points to the Templates folder, like this:
Doing so places an alias of the Templates folder right inside the OneDrive folder, as illustrated here:
And soon after you’ve created the directory junction, OneDrive will notice the new linked folder and sync it to the cloud:
Problem solved, right? Unfortunately, not so fast…
OneDrive doesn’t detect changes to the files in directory junction
While OneDrive synced the contents of the new linked folder when the directory junction was first established, it didn’t re-sync the folder when something changed.
For example, when we created a new file called “evaluation-2023.docx” in the linked folder, OneDrive didn’t copy the file to the cloud:
It’s as if OneDrive didn’t realize that the new file was there at all.
And the same was true for other changes too. OneDrive missed all deletes, renames and updates to the files in the linked folder. None made it to the cloud.
In fact, the only time OneDrive synced the linked folder was when the application started. Afterwards, OneDrive completely ignored the linked folder.
Needless to say, this unusual behavior renders the directory junction we created in the OneDrive folder useless. If we can’t rely on OneDrive to recognize changes to our files, why bother linking the folder at all?
The reason is likely very technical — rooted in the low-level file system services provided by the Windows Operating System.
OneDrive probably calls FindFirstChangeNotification to monitor the OneDrive folder. And whenever a file is changed:
FindFirstChangeNotification lets OneDrive know that something in the folder has been updated
OneDrive figures out what’s changed and copies the new file up to the cloud.
However, FindFirstChangeNotification treats directory junctions and other links specially. From the Symbolic Link Effects on File Systems Functions documentation:
Translation: FindFirstChangeNotification won’t shout when a file inside a directory junction changes. And unfortunately, that leaves OneDrive in the dark. 🙁