March 4, 2015

Sync any folder to OneDrive without moving it to local OneDrive folder

Problem

I’ve been using c:\work folder forever to store my work related semi-temporary files on my laptop hard drive. Although losing contents of that folder due to hard drive issue or similar wouldn’t cause much downtime in my work (as all important files are stored in SharePoint Online), I still didn’t feel too relaxed with the possibility of losing even 5 minutes of work in case that folder somehow disappeared.

Few times I’ve decided to move my c:\work to OneDrive for Business folder in order to sync work related files automatically to business version of OneDrive hosted in Office 365. However, each time I’ve got frustrated by the fact that finding the OneDrive folder in File Explorer is so difficult.

Sure, using Favorites or Quick Access (as in Windows 10), I can get there pretty easily, but still, it will add at least one additional folder level and lots of clikety clicks with my tired little mouse to get where I want to go. Plus, just looking at the left pane in File Explorer that is so full with garbage (several instances of OneDrive, DLNA devices just below This PC, Libraries, Control Panel?!, yet again same libraries, Desktop items at the root, etc.) makes me want to cry.

Solution

Use junction points to direct content from c:\work into your OneDrive folder, such as C:\Users\Jussi\OneDrive - Sulava Oy\Work. After creating junction point such as this, all content you add to c:\work will actually reside in the OneDrive folder, and are synced to OneDrive normally. And best of all, I can still use c:\work like I’ve always used.

Steps how to do this:
  1. Rename your existing c:\work (or whatever your folder is called) to e.g., c:\work_old
  2. Create Work folder into the OneDrive folder, e.g., C:\Users\Jussi\OneDrive - Sulava Oy\Work
  3. Open Command Prompt
  4. Type in mklink /j c:\Work "C:\Users\Jussi\OneDrive - Sulava Oy\Work"
  5. Move old content from c:\work_old to c:\work and confirm that Work folder under OneDrive folder starts syncing and eventually goes green
NOTE! As there is really just one instance of files on your hard drive, if you remove folder under OneDrive folder, it will also be removed from the junction point location.

15 comments:

  1. I have changed the content of the files and it did NOT update to OneDrive

    ReplyDelete
    Replies
    1. In your Work folder, confirm you see the change. Then confirm you see the change in your local Onedrive folder. If not, the junction point was not setup correctly. If yes, theis Onedrive sync is not working.

      Delete
  2. Yes you reversed source with destination - practically the real folder is in OneDrive and the link is on c:work ...... is this what you really wont ?!?!?

    ReplyDelete
    Replies
    1. Indeed, real folder is in Onedrive and c:) work is just pointing to that real Onedrive folder.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Does the order matter? Would this have the same result?

      >mklink /j "C:\Users\Jussi\OneDrive - Sulava Oy\Work" "c:\Work"

      Delete
  3. Thank you!!!!!!!!!!!!!!!!!!!!!!!!! It worked very fine in W10!!

    ReplyDelete
  4. What is the difference or the better way: Using a Junction (/J) or a Symbolic Link (/D)? I'm using Windows 10.

    ReplyDelete
    Replies
    1. In this case both should work as you're working winin your computer, difference between the two is more relevant if the junction/symlink target is file share on some other computer. Some deeper discussion on this can be found here: http://superuser.com/questions/343074/directory-junction-vs-directory-symbolic-link

      Delete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Thanks Mark for a nice link to Facebook!

      Delete
  6. Does this result in a true two way sync?

    ReplyDelete
    Replies
    1. Yes, two way sync works fine with this solution.

      Delete
  7. Thanks for your good command.
    But when I create a link, link is successfully created in cmd, but when I try to open shortcut file in local drive, it gives" access is denied, file name,directory or syntax is invalid".

    ReplyDelete
    Replies
    1. Hi, hard to say what could be causing it. By "link" do you mean the junction point? If by "link" you mean shortcut file link, then it might be that those are not supported, normal files work fine though.

      Delete