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 the cloud), 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 items (several instances of OneDrive, DLNA devices just below This PC, Control Panel?!, yet again same libraries, Desktop items at the root, Music, Videos, Pictures, 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. Open Command Prompt
  2. Type in mklink /j c:\Work "C:\Users\Jussi\OneDrive - Sulava Oy\Work"


NOTE! If the command above doesn't work, you may not be able to create symbolic link to an existing folder, in that case use steps:
  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.

24 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. Does the order matter? Would this have the same result?

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

      Delete
    3. No, the syntax is mklink [[/d] | [/h] | [/j]] {Link} {Target}, so first you need to define where you want the new folder to be (Link), and only after that where it is really pointing to (Target).

      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. Does this result in a true two way sync?

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

      Delete
  6. 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
  7. The initial MOVE and Rename is not of any value, you can simply place a Junction (or sym Link) directly into the one drive folder to accomplish this.

    IE change this to one Step:

    1) Type in mklink /j "C:\Users\Jussi\OneDrive - Sulava Oy\Work" "c:\Work"

    ReplyDelete
    Replies
    1. Thanks, apparently something has changed in more recent versions of Windows as you can now point it to an existing folder. Instructions updated.

      Delete
  8. I've just done this and it syncs perfectly. My question is if the original folder gets deleted, does the folder in OneDrive with all it's content get deleted as well?

    ReplyDelete
    Replies
    1. If you delete the ORIGINAL folder, i.e., "C:\Users\Jussi\OneDrive - Sulava Oy\Work" in my case, it will be deleted from OneDrive. If you delete the junction point, i.e., "c:\work", it will just delete the junction point and the actual folder will remain intact.

      Delete
  9. I tried the above, the link is created and I can see a green check mark on each folder , yet the files are not synching with one drive any thoughts?

    ReplyDelete
    Replies
    1. If you just did it. Maybe wait a few minutes depending on how much file you have. If nothing happens after a while then maybe delete it and try the process again.

      Delete
    2. I left it overnight and nothing...~80GB

      Delete
  10. Hi,

    instead of "work" was planning to use this idea to keep back-up of personal staff (located in FAT32 / SD-card),which I don\t want to be on C-drive.

    So on CMD made "mklink /j D:\Omat "C:\Users\xxxxxx\OneDrive - xxx\SD-card-Omat" "
    This created error "Local NTFS volumes required to complete the operation".

    As would like to keep as FAT32 (to avoid complications when using in other PC), any workaround in mind?

    Thanks in advance

    Esa

    ReplyDelete
  11. Junction point is NTFS feature and I'm not aware of any workaround for FAT32. :(

    ReplyDelete
  12. Hello, you have bad syntax, both target and link should be in apostrophes.

    ReplyDelete
    Replies
    1. Apostrophes are not needed if the path doesn't contain spaces.

      Delete