HomeWinBuzzer TipsHow to OneDrive Sync Any Local Folder with Mklink

How to OneDrive Sync Any Local Folder with Mklink

We show you how to create a OneDrive mklink so you can OneDrive folder sync any local directory to with your cloud drive.

-

OneDrive, 's premier solution, offers and users a convenient way to back up essential files. Yet, a common challenge is that OneDrive's synchronization is limited to its designated folder. This limitation can be a hurdle when you want to seamlessly back up diverse data types such as images, downloads, or game saves. Luckily, you can bypass it using mklink, a command-line tool in Windows that creates symbolic links or directory junctions, allowing any local folder to sync with OneDrive.

Understanding OneDrive Mklink

Mklink creates symbolic or hard links in Windows, essentially making the system treat linked directories and files as if they were physically present in the target location. This capability is pivotal for our purpose, as it allows us to make OneDrive “believe” it's directly managing files that are, in fact, stored elsewhere on your PC.

A symbolic link or symlink acts as a reference or shortcut to another file or directory. It's particularly useful for creating accessible shortcuts to files/folders located in different directories or volumes without moving the actual data.

This guide will walk you through a clever workaround using mklink to extend OneDrive's sync capabilities to any directory of your choosing.

⚠️ Please note: The process described below is the same in  as it is in .

How to Sync A Local Folder to OneDrive Using Mklink

Symbolic links can bridge the gap between local folders and your OneDrive cloud storage. By creating a symbolic link, you make OneDrive recognize a local folder as part of its own structure, enabling sync without moving the actual folder.

  1. Open Command Prompt or PowerShell with Administrator Privileges
     
    Hit the “Windows” key, type “CMD” or “PowerShell” and click on “Run as administrator“.
     
    Windows 11 Open CMD as admin

  2. Create a OneDrive mklink to add a folder to OneDrive
     
    Familiarize yourself with the mklink command structure: mklink /J "Link" "Target", where /J creates a directory junction, “Link” is the path in OneDrive, and “Target” is the local folder you wish to sync.
     
    You can use the mklink command to create a direct link between your local folder and the OneDrive sync folder, allowing the contents of the local folder to be synced as if they were part of the OneDrive folder.
     
    Construct Your Mklink Command
     
    Here we use “LinkedFolder” as an example. Replace it with the folder you want to do an Mklink OneDrive folder sync with:
     
    In the Command Prompt, type the mklink command with your specific paths as mklink /J "%UserProfile%\OneDrive\LinkedFolder" "C:\LocalFolder" to sync “C:\LocalFolder” with OneDrive.
     
    Here we use “C:\Users\Winbuzzer\Documents” as an example:
     
    Windows 10 - Command Prompt - Type the Command

    Execute the Command
     
    Press Enter to execute the command. A message will confirm the creation of the junction, indicating that the link has been successfully established.

  3. Verify the Sync: Check the OneDrive Folder
     
    After creating the symbolic link, the next step is to ensure that the local folder is properly syncing with OneDrive.

     
    Navigate to your OneDrive folder. You should see the linked folder appear here, symbolized by an icon with the shortcut symbol in the lower left corner. You will see the cloud symbol if it's fully synced with the OneDrive cloud.
     
    Windows 10 - OneDrive Location

  4. Test Mklink OneDrive File Synchronization
     
    Add or modify a file in your local folder and check if the changes are reflected in the OneDrive folder. This confirms the sync is active.

Managing and Troubleshooting Your Mklink OneDrive Sync

Maintaining the sync involves understanding how changes to files are handled and what to do if the sync doesn't work as expected.

  1. Monitor Storage and Data Usage

    Keep an eye on your OneDrive storage limit and your internet data usage, especially if you're syncing large folders.

  2. Troubleshoot Sync Issues

    If changes aren't syncing, ensure OneDrive is running correctly, and try restarting OneDrive or your PC. Check for any permission issues, especially if the linked folder contains system or application files.

FAQ – Frequently Asked Questions about Mklink OneDrive Folder Sync

Can I sync multiple folders with OneDrive using mklink?

Yes, you can sync multiple folders by creating separate mklink commands for each folder you wish to sync with OneDrive. Ensure each command specifies a unique name for the link in the OneDrive directory.

How do symbolic links affect file backup and recovery in OneDrive?

Files accessed through symbolic links are backed up and recoverable in OneDrive just like any directly stored file. However, the symbolic link itself is not backed up, only the content it points to.

What should I do if I encounter a ‘Maximum Path Length Limit' error when using mklink with OneDrive?

This error occurs when the file path exceeds Windows' maximum limit. To resolve it, shorten the path by renaming folders or files to shorter names or by restructuring your directory hierarchy.

Can I use mklink to sync OneDrive with cloud services other than OneDrive?

Mklink creates links at the file system level, so it can't directly sync between OneDrive and other cloud services. However, you can sync a local folder with OneDrive using mklink and then use another service's sync tool to sync that local folder.

How does mklink handle file conflicts or duplicates in OneDrive?

File conflicts or duplicates are handled by OneDrive's built-in conflict resolution mechanism, which might prompt you to choose which version to keep or automatically create a copy of the conflicting file.

Is it possible to use mklink with OneDrive for Business accounts?

Yes, mklink works with OneDrive for Business in the same way as it does with personal OneDrive accounts, allowing you to sync local folders to your business account.

How can I automate the creation of mklink junctions for multiple folders?

You can automate mklink junction creation by writing a batch script or PowerShell script that executes mklink commands for each folder you want to sync with OneDrive.

What happens to the symlink if the OneDrive folder is renamed or moved?

If the OneDrive folder linked to the symlink is renamed or moved, the symlink will break, resulting in an error when accessed. You'll need to recreate the mklink with the new path.

Can I exclude specific files or subfolders in a symlinked folder from syncing with OneDrive?

Excluding specific files or subfolders within a symlinked folder from syncing requires using OneDrive's built-in selective sync feature or file/folder attributes to exclude them from syncing.

How do I sync folders outside my user profile, like a folder on a different drive?

To sync a folder outside your user profile, such as on a different drive, use mklink with the full path to the target folder and ensure the drive is always connected to maintain the sync.

What are the security implications of using mklink with OneDrive?

Using mklink can expose linked folders to cloud sync, potentially leading to sensitive data being stored in the cloud. Always ensure that the data you sync is appropriate for cloud storage in terms of privacy and security.

Can I use mklink to undo changes made in a OneDrive-synced folder?

Mklink itself doesn't provide version control or undo functionality. To revert changes, you would need to use OneDrive's version history feature for individual files.

How do I update a symlink to point to a new folder without losing the current OneDrive sync state?

To update a symlink, first, remove the existing link, then create a new link command pointing to the new folder. OneDrive will sync the new folder's contents as it did with the original.

Does using mklink with OneDrive increase network or system resource usage?

Syncing additional folders via mklink can increase network and system resource usage due to the increased amount of data being synced. Monitor your system and network performance to manage resource usage.

How can I troubleshoot issues where OneDrive is not recognizing changes in a symlinked folder?

If OneDrive doesn't recognize changes, ensure OneDrive is running and syncing correctly, check for permission issues in the symlinked folder, and verify that the symlink is still valid and hasn't been broken.

Extra: How to Use TeamViewer to Fetch Files from a Remote PC

In 2020, Microsoft discontinued OneDrive fetch, which let you grab any file on your PC via OneDrive, It did not need to be in your OneDrive, Documents, Pictures, or Desktop folder – and be in Program Files or any random directory. If you want to continute to remoteley access all files without uploading them to the cloud, you can use TeamViewer as a free replacement for the OneDrive Fetch Files Feature.
 

Extra: How to Use OneDrive Personal Vault to Passwort-Protect Your Files

OneDrive Personal Vault adds an additional layer of security to your most important files. When users save a document or photo to their OneDrive vault, they can only access it via an additional method of authentication. In our other guide, we show you how to set up a OneDrive Personal Vault on Windows 11 or Windows 10.
 
Featured - How to Use OneDrive's “Personal Vault” to Secure Your Files

Markus Kasanmascheff
Markus Kasanmascheff
Markus is the founder of WinBuzzer and has been playing with Windows and technology for more than 25 years. He is holding a Master´s degree in International Economics and previously worked as Lead Windows Expert for Softonic.com.
Table of Contents: