A - Introduction
Microsoft OneDrive is a file-hosting service operated by Microsoft. First released in August 2007, it allows registered users to store, share and sync their files. OneDrive also works as the storage backend of the web version of Microsoft 365 / Office.
In this article, we will describe to add Folder/File, that is outside of OneDrive Folder, into OneDrive without Moving.
- A - Introduction
- B - Issue
- B -1 - OneDrive Default Folder and Contents
- B -2 - Add a Folder/File that is outside of OneDrive Folder into OneDrive without Moving
- C - Solution --- Implementation
- D - Concept: What and Why
B - Issue
OneDrive is the cloud storage solution for Microsoft’s 365 Service. Out of the box, it selects the most common locations for important files, and it synchronizes data within those locations to the cloud. This is a great solution so long as your workflows are not “outside the box” that Microsoft gives you to play with. But
- What if your system utilizes multiple drives?
- What if you just like to store files in other places because it works better for you?
B -1 - OneDrive Default Location and Contents
Location
Out of the box, usually, the OneDrive folder is at location: c:\Users\<username>\OneDrive, such as
or
Contents
From Windows Task Bar => Click OneDrive Icon => Click Help & Settings on the top right corner:
In the OneDrive Settings Window => Click Account => Click Choose Folders.
The subFolders in OneDrive will be shown like this.
You can choose to hide some folders you do not like them in local OneDrive (File Explorer), i.e., they are stored in OneDrive Server (Cloud), but not synchozied to your local.
B -2 - Add Folder/File outside of OneDrive Folder into OneDrive without Moving
Add Folder/File into OneDrive
It is simply just adding the folder or file you want into the OneDrive Folder or sub Folder:
Add Folder/File outside of OneDrive Folder into OneDrive:
However, in some circumstances, one wants to keep folders or files outside of the OneDrive Folder while still wanting to store them in OneDrive on Cloud. For example, the folder SNV and Temp under the root directory:
SVN folder is a local SVN cloned repository. By system setup, it is required to be in this certain location,
while the Temp folder, by habit, it is used for TortoiseSVN patch file stored location. For consistency, it is better to be kept in that location.
Now, the issue is how to add these Folders/Files that are outside of OneDrive Folder into OneDrive without Moving them.
C - Solution --- Implementation
We use the command, mklink to create a directory or file symbolic or hard link to link the folders/files to the OneDrive Folder.
We have these two folders that will be moved into OneDrive:
and this file too:
Open a command link console with admin right, then type the three mklink commands:
- mklink /d C:\Users\gghan\OneDrive\mySQL C:\SQL2019
- --- Make a symbolic link between folders
- mklink /j C:\Users\gghan\OneDrive\mySWSetup C:\SWSetup
- --- Make a Junction between folders
- mklink /h C:\Users\gghan\OneDrive\myFile.txt C:\temp\myTestFile.txt
- --- Make a hard link between two files:
like these:
After moving the folders and files, in the OneDrive Settings window, we can see the two linked or newly added Folders:
While in the File Explorer, we can see these two folders and a file within the OneDrive Folder:
We can use rd and del commands to remove the symbolic olders and delete the hard-linked file
- rd C:\Users\gghan\OneDrive\mySQL
- --- Remove a symbolic link between folders
- rd C:\Users\gghan\OneDrive\mySWSetup
- --- Remove a Junction between folders
- del C:\Users\gghan\OneDrive\myFile.txt
- --- Delete a hard link between two files
Like these:
Note. Whatever you add a folder./file into local OneDrive, or Symbolic (junction) to a folder/file to your Local OneDrive, it will be uploaded to online (Cloud), but not automatically download to your other computer when you access the same OneDrive Account there.
For the three folders we added in this article, we can see them, online storage:
This is a view from another computer for its local OneDrive.
D - Concept: What and Why
Junction points and symbolic links are features of NTFS that permit file system resources to be accessed via alternate paths. We will not discuss the details about junction and symbolic links, nor the differences between them (can be seen in article Pete Hinchley: Junctions and Symbolic Links). We only indicate that in a local machine, they are action the same as a link between folder to folder while the hard link is a link between file to file.
Now, in the scope of our discussion, I will address the difference between, say, the shortcut and the links (junction, symbolic link, hard link), then we can have a concept of what the symbolic link is.
Difference between a Symbolic Link and a Shortcut
mklink is used for making links like shortcuts, but not shortcuts
A shortcut is a distinct file (with its own unique properties) that links to another file or directory. Say, if we create a shortcut for folder: C:\SQL2019 and move it into OneDrive:
When we CLICK the shortcut, it will go back to the original Path:
A junction acts like a pseudonym and, unlike a shortcut, provides transparent access to the target, even via a command prompt. As we discussed above, if we make a junction into OneDrive for the folder: C:\SQL2019, such as
When Click the junction icon, we will get to a new path within OneDrive:
It is like we are going home from office. Usually, we will go home directly through the Blue Path, sometimes, we may go to shopping center through the red Path first, then go home. From shopping center to home, we have two ways to go, Suppose iwe have a short cut, pointing to the original home path, the Blue Path, then we Click the shortcut, we are back to the Blue Path, we use the same Path as usual home. We can also go forward along the Green Path home, which is totally different Path from the Original Blue Path.
i.e., The shortcut points back to the original Path, while the Green Path, the second Path, is like the symbolic link, which is a different Path from the original one, the Blue Path.
References