Synchronizing any folder on your system with OneDrive


David Meego - Click for blog homepageIn my last post: Backup regimes and synchronizing folders across your network, I discussed my method of backing up data from four folders off the root of the drive across my network and how I use the free SyncToy 2.1 tool from Microsoft.

So in this post I wanted to take it to the next level.

 

Introducing the Cloud

Here is the next bit of the puzzle.... Cloud storage. Everything so far has been based on local hard drives, but I have OneDrive storage and wanted to use that at least for My Documents and the Music and Pictures from my Media. This would make those three areas of my data available from anywhere I had an internet connection including my Windows Phone.

I am using Office 365 to provide Microsoft Office to the family (it allows 5 machines). It also provides 1TB of OneDrive storage per user.

When OneDrive is installed (or comes with Windows 8.1) it sets up a single folder in the user folders and will Synchronize anything in that folder with OneDrive storage in the cloud.

So how can I get OneDrive to synchronize with my folders C:\My Documents, C:\Media\Music and C:\Media\Pictures as well as the existing data (such as OneNote files and the phones camera roll).

One article I read on the topic, said to Pause Syncing by right clicking on the OneDrive icon in the system tray and then move the desired folders into the OneDrive folder and then resume Syncing. However, that MOVED the folders into a user folder: Exactly the thing I was trying to avoid by using folders off the drive's root folder. It would also break all the SyncToy configuration that I already have in place. So that is no good.

I wanted a method of mapping a folder from the data I want synchronized to the OneDrive folder.

Using a shortcut to the folder did not work as OneDrive just backed up the .lnk file. Most of the mapping techniques I found either mapped a network drive to a drive letter, or mounted a drive into an empty folder (the method I used with the micro SD card).

By then I found this article (and later this article) with the method I was looking for. It contained the command a "directory junction" on the Window NTFS File system. While the folder can point to a different location, OneDrive sees it as just another folder and will sync it as normal.

mklink /J  "C:\Users\<USERNAME>\OneDrive\<Folder>" "C:\<Folder>"

Note: You will need to change the <USERNAME> and <Folder> placeholders. For older machines, you might find that the OneDrive folder is actually still called SkyDrive.

I used the %USERPROFILE% environment variable and a little bit of batch file logic to create a batch file which will create the links for me on demand. 

I have attached the two batch files (one for the My Documents folder and one for the Media\Music and Media\Pictures folders) to the bottom of this article.

 

Notes 

Here are some guidelines that I think will make the OneDrive approach to synchronization work better.

  • Don't try to use both OneDrive synchronization and SyncToy synchronization at the same time for the same folders.
     
  • I suggest moving your data out of the folder you are creating the link to, so the folder is initially empty. Then on each machine linked to the same OneDrive account, run the mklink command and wait for OneDrive status to say "Files are up to date".
     
  • Then you can copy the files into the folder on one machine and let OneDrive upload them to the cloud storage. Then OneDrive on the other machines should bring the files down again. This should avoid the issue where OneDrive creates duplicates of the files when it finds files already existing.
     
  • If you have a lot of data, you will be using a significant amount of your internet allowance (unless you are unlimited) to send and receive all the files to multiple machines.
     
  • If your internet speed (especially upload speed) is slow, this process can take a long time for the initial upload and downloads.

 

Hope you found this information useful.

David

PS: After finding the process too slow and getting too many duplicated files, I decided to stick with my SyncToy method for the My Documents folder as it was faster and more reliable.

PPS: I am still uploading my Music and Pictures to a secondary OneDrive account that I don't use as a primary account on any machines. This is creates a "cloud" backup, but will not be synchronized to any other machines.

Map to OneDrive.zip

Comments (25)

  1. old coder says:

    IMHO, needing them to be in the root folder makes this more difficult than it needs to be. For all non-work PCs OneDrive is the default documents folder. Once you manually change the various built-in library folders (pictures, videos, etc…) to point to a OneDrive folder then new items will automatically be backed up to OneDrive. Let it spend the first half day syncing up whatever monster music collection you have (lots of files = lots of overhead). Once it's done you'll never lose them.

    File History can serve a similar backup function – I used to back up to an external usb drive attached to my wifi router but honestly see no need any more as long as I use the folders designated by the operating system for documents, videos, pics, etc… OneDrive is more than enough.

  2. David Musgrave says:

    Hi old coder

    The default folders put the documents, pictures, music etc. into a user folder which is not easily accessible when you log into the machine as a different user.  A few of the machines in my network are accessed by multiple users and we want all the files accessible regardless of user used.

    As long as it works for you, that's great.

    David

  3. Kate says:

    Thanks a bunch for the tip, David! I have over 150GB of images for my landscape photography work and your symlink solution worked to get OneDrive to back them up. I have my images on a separate SSD from my boot disk so I was forced to send them to OneDrive manually (what a pain!) but this way I was able to link my SyncToy nightly backup directory on my local RAID array to OneDrive and have everything automatically upload.

  4. Eugene says:

    HI, Isn't there a way to right click on a folder/file through ms explorer and select (i forgot the exact term) "sync with onedrive" or something? I KNOW i was able to do it a while back but since then I have replaced my primary OS Disk then recently had another storage disk fail on me, fortunately I had one of the folders on that failed disk linked to onedrive so it alone was saved, Unfortunately that was the only folder saved, anyway How do i get that right-click option back? The folder wasn't moved to the onedrive folder and I don't remember doing anything with cmd or outside apps just right-click folder and sync…. I can't seem to find what it on a google search.

  5. NK says:

    Seems symlinks are no longer supported by OneDrive in Windows 8.1

  6. BB says:

    Thanks for the warning NK, was just about to try this on 8.1.

  7. David Musgrave says:

    I had it working fine with Windows 8.1 when the article was written. The article even references Windows 8.1.

    NK and BB, I suggest you try it again.

    David

  8. NK says:

    I will try again, but my first attempt failed, and then I saw this as confirmation: http://www.howtogeek.com/…/how-to-sync-any-folder-with-skydrive-on-windows-8.1

  9. Anonymous says:

    As it turns out – Directory Junctions can only be used on local volumes. Network drives cannot be mapped using mklink – which is sad.

    So I guess, the headline should be changed to read; synchronizing-almost-any-folder-on-your-system-with-onedrive

  10. cam says:

    wow your making this way more complex than it actually is man…

  11. Newcomer says:

    I have a NAS storage server, is there a way to map the drives to a folder and have it sync to Onedrive.

  12. 14Data says:

    I think it’s confirmed below but I’ve tried this on Windows10 to an external HDD. It appears to only work one way. I can add files to OneDrive and they appear everywhere, but if I add them to the external HDD they are not replicated to OneDrive. Is this expected or have I missed something?
    I’ve tried the same with the folder elsewhere on an internal HDD and it all works OK as expected.

  13. A: Kleine says:

    Thank you very much, this is exactly what I was looking for, and it works perfectly!

  14. Hein du Plessis says:

    Awesome, thanks for this!

  15. Kimbrley says:

    I am trying to get onedrive windows 10 to sync a folder which is located on a Synology NAS network drive.
    Can someone please confirm whether or not windows 10 allows mklink to create a folder link inside c:/onedrive to trick onedrive into syncing the folder on the network drive?
    Thanks

    1. Alistair says:

      It can but the problem is that if you’d ever have to reset the OneDrive sync it will look at how much data is stored in the cloud and compare it to how much space is available on the drive holding the root OneDrive folder. The cloud storage can be larger than your root drive because you’ve faked it into backing up your NAS storage via the junction.

      So junctions are cool but OneDrive is too clever about protecting the user. I have Office 365 with 1TB, a 100GB SSD in my laptop (C:) and my pictures, music, videos on a HD in the drive bay (D:). After a reset on OneDrive I can no longer sync everything because it says there is not enough room on C: even though I’ve junctioned all the big stuff to D:. My solution seems to be to move my OneDrive root to D: and junction Documents to C:. This should work as I have enough free space on D:. But what a pain!

  16. Mark C Yorkovich says:

    This is a great help to adding other folders to be synced to OneDrive. Thanks! I have one question, though: It’s my understanding that if a folder is deleted in OneDrive, then it will be deleted in the cloud and that deletion will be propagated to any other computers linked to the OneDrive account. For instance, if I sync my Desktop folder using “mklink /J “%USERPROFILE%\OneDrive\My Desktop” “%USERPROFILE%\Desktop”, how can I remove the OneDrive synchronization without deleting the My Desktop folder and its contents?

    1. Greg says:

      By removing the Symlink you created in %USERPROFILE%\OneDrive with that command like any usual file the original “My Desktop” Folder will not be deleted!

      (Remove “%USERPROFILE%\OneDrive\My Desktop” it’s a symbolic link not the original folder)

  17. Hao says:

    In Windows 10, mklink cannot link a network drive. Always got “local volumes are required to complete the operation”, but external hard drive works.

    Not sure it’s just me or some changes Micro$oft made.

    Hao

    1. Greg says:

      You can change this behavior by configuring the following Group Policy setting:

      Computer Configuration\Administrative Templates\System\NTFS File System\Selectively Allow The Evaluation Of A SymbolicLink

      When you enable this policy setting, you can select from four settings:

      Local Link To Local Target Enabled by default, this allows local symbolic links to targets on the local file system.

      Local Link To Remote Target Enabled by default, this allows local symbolic links to targets on shared folders.

      Remote Link To Remote Target Disabled by default, this allows remote symbolic links to remote targets on shared folders.

      Remote Link To Local Target Disabled by default, this allows remote symbolic links to remote targets on shared folders.

      http://sourcedaddy.com/windows-7/how-to-create-symbolic-links-to-shared-folders.html

  18. CoolDude says:

    You are brilliant

  19. CoolDude says:

    You are brilliant

  20. mackarof says:

    guys,
    this is wrong
    mklink /J “C:\Users\\OneDrive\” “C:\”

    it should be
    mklink /J “C:\Full\Path\Link to be created” “C:\Full\Path\To\OneDrive\Existing Target Name”

    otherwise junction link will not be synced…

    1. Hi mackarof

      I have folders off my c:\ drive root which I don’t want to move, but do want to have synchronized.

      So I have added the directory symbolic links to the OneDrive folder pointing to the existing folders.

      You are going the other way. Existing OneDrive folder made available off root folder.

      This might work better for automatically synchronise, but the synchronising does work the way I have it, but it does not always start immediately. If it does not, you can always pause and resume the Onedrive process to make it sync.

      Thanks for your comments.

      David

Skip to main content