{"id":12042,"date":"2023-08-09T04:20:06","date_gmt":"2023-08-09T11:20:06","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=12042"},"modified":"2023-08-09T04:20:31","modified_gmt":"2023-08-09T11:20:31","slug":"onedrive-directory-junctions","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/onedrive\/onedrive-directory-junctions\/","title":{"rendered":"OneDrive Doesn&#8217;t Sync Directory Junctions"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" style=\"margin-bottom:20px;\" src=\"\/blog\/images\/onedrive-warning-350x272.webp\" title=\"OneDrive Doesn't Sync Linked Folders\" alt=\"OneDrive Doesn't Sync Linked Folders\" border=\"0\" width=\"350\" height=\"272\"\/><\/div>\n<h2 class=\"blog-caption\">What is a directory junction?<\/h2>\n<p>A directory junction is an alias of one folder to another.<\/p>\n<p>Put another way, a directory junction allows you seamlessly access the contents of a folder from another directory, with a different path.<\/p>\n<p>For example, let&#8217;s say that you have folder &#8220;C:\\Users\\Username\\Documents\\Media\\All Movies&#8221; on your computer. However, you find that directory too long to type when working with it from the command line. You dream of entering a shorter path &mdash; such as &#8220;C:\\Movies&#8221; &mdash; but you don&#8217;t want to copy the files to a new location.<\/p>\n<p>To solve the problem, you would create a directory junction mapping &#8220;C:\\Movies&#8221; to &#8220;C:\\Users\\Username\\Documents\\Media\\All Movies&#8221;. After doing that, all your movies will be accessible from &#8220;C:\\Movies&#8221; too. For all practical purposes, &#8220;C:\\Movies&#8221; becomes a synonym for the longer path.<\/p>\n<p>Directory junctions can be created with the with the <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/mklink\" target=\"_blank\" rel=\"noopener\">mklink command<\/a>. For example, this command creates the alias for the scenario above:<\/p>\n<blockquote><p>mklink \/j &quot;C:\\Movies&quot; &quot;C:\\Users\\Username\\Documents\\Media\\All Movies&quot;<\/p><\/blockquote>\n<h2 class=\"blog-caption\">Why use a directory junction with OneDrive?<\/h2>\n<p>A directory junction provides convenience and flexibility when designing your cloud synchronization strategy. In theory, by allowing you to place any arbitrary folder inside your OneDrive folder, you can extend the scope of your OneDrive backup without having to duplicate large folders and files.<\/p>\n<p>Let&#8217;s illustrate with a practical example.<\/p>\n<p>Say you&#8217;ve installed OneDrive to synchronize your OneDrive folder (&#8220;C:\\OneDrive&#8221;) with the cloud. Everything is working well.<\/p>\n<p>However, you also want OneDrive to backup &#8220;C:\\Shared\\CustomerSuccess\\Templates&#8221; &mdash; a shared folder with important company files. How do we instruct OneDrive to sync that folder as well?<\/p>\n<p>Well, this is where folder linking comes in. You can create a directory junction in your OneDrive folder that points to the Templates folder, like this:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/create-directory-junction.png\" class=\"zoomPopup\" title=\"Create a directory junction with mklink\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/create-directory-junction.png\" title=\"Create a directory junction with mklink (click to enlarge)\" alt=\"Create a directory junction with mklink\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<p>Doing so places an alias of the Templates folder right inside the OneDrive folder, as illustrated here:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/directory-junction-created-in-onedrive.png\" class=\"zoomPopup\" title=\"The directory junction in the OneDrive folder\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/directory-junction-created-in-onedrive.png\" title=\"The directory junction in the OneDrive folder (click to enlarge)\" alt=\"The directory junction in the OneDrive folder\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<p>And soon after you&#8217;ve created the directory junction, OneDrive will notice the new linked folder and sync it to the cloud:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/onedrive-linked-folder-synced.png\" class=\"zoomPopup\" title=\"OneDrive has synced the linked folder\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/onedrive-linked-folder-synced.png\" title=\"OneDrive has synced the linked folder (click to enlarge)\" alt=\"OneDrive has synced the linked folder\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<p>Problem solved, right? Unfortunately, not so fast&#8230;<\/p>\n<h2 class=\"blog-caption\">OneDrive doesn&#8217;t detect changes to the files in directory junction<\/h2>\n<p>While OneDrive synced the contents of the new linked folder when the directory junction was first established, it didn&#8217;t re-sync the folder when something changed.<\/p>\n<p>For example, when we created a new file called &#8220;evaluation-2023.docx&#8221; in the linked folder, OneDrive didn&#8217;t copy the file to the cloud:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/onedrive-new-file-not-synced.png\" class=\"zoomPopup\" title=\"OneDrive doesn't sync a new file in the linked folder\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/onedrive-new-file-not-synced.png\" title=\"OneDrive doesn't sync a new file in the linked folder (click to enlarge)\" alt=\"OneDrive doesn't sync a new file in the linked folder\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<p>It&#8217;s as if OneDrive didn&#8217;t realize that the new file was there at all.<\/p>\n<p>And the same was true for other changes too. OneDrive missed all deletes, renames and updates to the files in the linked folder. None made it to the cloud.<\/p>\n<p>In fact, the only time OneDrive synced the linked folder was when the application started. Afterwards, OneDrive completely ignored the linked folder.<\/p>\n<p>Needless to say, this unusual behavior <b>renders the directory junction we created in the OneDrive folder useless<\/b>. If we can&#8217;t rely on OneDrive to recognize changes to our files, why bother linking the folder at all?<\/p>\n<h2 class=\"blog-caption\">But&#8230; why?<\/h2>\n<p>The reason is likely very technical &mdash; rooted in the low-level file system services provided by the Windows Operating System.<\/p>\n<p>OneDrive probably calls <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/fileapi\/nf-fileapi-findfirstchangenotificationw\" target=\"_blank\" rel=\"noopener\">FindFirstChangeNotification<\/a> to monitor the OneDrive folder. And whenever a file is changed:<\/p>\n<ol>\n<li>\n<p>FindFirstChangeNotification lets OneDrive know that something in the folder has been updated<\/p>\n<\/li>\n<li>\n<p>OneDrive figures out what&#8217;s changed and copies the new file up to the cloud.<\/p>\n<\/li>\n<\/ol>\n<p>However, FindFirstChangeNotification treats directory junctions and other links specially. From the <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/fileio\/symbolic-link-effects-on-file-systems-functions#findfirstchangenotification\" target=\"_blank\" rel=\"noopener\">Symbolic Link Effects on File Systems Functions<\/a> documentation:<\/p>\n<div class=\"blog-qa-question-box\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.png\" width=\"21\" height=\"21\" \/>&nbsp;If the path points to a symbolic link, the notification handle is created for the target. If an application has registered to receive change notifications for a directory that contains symbolic links, the application is only notified when the symbolic links have been changed, not the target files.<\/p>\n<\/div>\n<p>Translation: FindFirstChangeNotification won&#8217;t shout when a file inside a directory junction changes. And unfortunately, that leaves OneDrive in the dark. \ud83d\ude41<\/p>\n<div style=\"margin-top:30px\" align=\"center\">\n<div class=\"cta-button-1\">\n<table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"left\">\n<tbody>\n<tr>\n<td align=\"center\"><a href=\"\/blog\/tag\/onedrive\/\" title=\"More about running OneDrive as a Windows Service\"><span><nobr>Read more articles about OneDrive&#8230;<\/nobr><\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/onedrive\/how-to-turn-off-files-on-demand\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"How to Turn Off Files On-Demand in OneDrive\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/onedrive-files-always-available-150x150-1.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">How to Turn Off Files On-Demand in OneDrive<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/onedrive\/onedrive-support-ending\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"OneDrive Will Soon Stop Working on Windows 7, 8 and 8.1\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/onedrive-problem-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">OneDrive Will Soon Stop Working on Windows 7, 8 and 8.1<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/onedrive-fails-in-session-0\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Investigating OneDrive Failures in Session 0 on Windows Server\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/onedrive-not-synching-files-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Investigating OneDrive Failures in Session 0 on Windows Server<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>What is a directory junction? A directory junction is an alias of one folder to another. Put another way, a directory junction allows you seamlessly access the contents of a folder from another directory, with a different path. For example, &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/onedrive\/onedrive-directory-junctions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":12077,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[204],"tags":[319,322,320,110,321],"class_list":["post-12042","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-onedrive","tag-directory-junction","tag-findfirstchangenotification","tag-mklink","tag-onedrive","tag-symbolic-link"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=12042"}],"version-history":[{"count":16,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12042\/revisions"}],"predecessor-version":[{"id":12123,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12042\/revisions\/12123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/12077"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=12042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=12042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=12042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}