OneDrive is great for backing up data to the cloud, but one of its limitations is that you are only allowed to specify a single folder. I had an application that I used frequently between two computers, and I needed to manually copy files between the computers any time I changed settings.
After doing a bit of research, I found a great solution utilizing OneDrive and junctions created using mklink. The secret to this approach is to keep the “real” files in your OneDrive folder, and then create the links from the original path.
Here’s a quick example to demonstrate. Let’s assume I have a directory c:\users\adam\foo\settings that I want to sync between computers. I would perform the following steps:
- Make a backup of c:\users\adam\foo\settings just in case something goes wrong.
- Copy settings into my OneDrive folder → c:\users\adam\onedrive\foo\settings
- Delete c:\users\adam\foo\settings
From a command prompt, run the following:
mklink /j "c:\users\adam\foo\settings" "c:\users\adam\onedrive\foo\settings
That takes care of one PC so that it will use the files that are now contained in the OneDrive folder, but it’s only half the battle. Now we need to switch over to the other PC and configure it to use the OneDrive files, too. I’ll use a different username in my path to help illustrate that these steps are being performed on computer #2.
- Make a backup of c:\users\adam.prescott\foo\settings
- Delete c:\users\adam.prescott\foo\settings
From a command prompt, run the following
mklink /j "c:\users\adam.prescott\foo\settings" "c:\users\adam.prescott\onedrive\foo\settings"
Now both computers are configured to use the files contained in the OneDrive folder, and changes will sync between them as changes are made. Perfect!
One thought on “Sync Any Folder Between PCs with OneDrive”
mklink /j “%userprofile%\foo\settings” “%userprofile%\onedrive\foo\settings
saved as %userprofile%\foo\createlink.bat