Fixing Long Path Names in Windows for Synced SharePoint Files
Although both Windows and SharePoint can handle longer path and file names than they used to, both are still far behind user behavior, which leans more toward encyclopedic names than the old 8.3 standard of yesteryear. Windows 10’s maximum path length is 260 characters, and you might think that’s plenty to accomplish whatever a person might need, but you’d be wrong. I frequently find folders and files on share drives named with entire sentences, punctuation and all. Now, having migrated almost all of my on-premises network shares up to Teams and SharePoint, users are rediscovering the value of brevity.
Instead of a finding their files behind a drive letter, they are syncing them to their local hard drives using the OneDrive desktop client. Where a file used to be at “G:\My really long folder name“, now it’s at “C:\Users\John.Doe\My Organization Name\My Team Name – Private Channel – Private Channel\My really long folder name“.
That’s more than 80 characters extra. I’m sure you can see why they might be hitting the maximum character counts for path names.
You Can’t Save Here
Here are some of the error messages you might encounter in this scenario:
Destination Path Too Long
The file name(s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorter path.
You will see this error if you already have a path that is at its maximum character count and you try to create another subfolder.
The file name you specified is not valid or too long. Specify a different file name.
You will see this error if a file was synced from SharePoint/Teams/OneDrive with a name that puts it over the maximum character count and you try to rename it to something that isn’t short enough to meet the path length criteria.
Microsoft Word (or any other Office 365 application Save As dialog box)
You can’t save here. Please choose another location.
You will see this error if you try to save an Office 365 document with a name that would exceed the maximum character count. Interestingly, Notepad and other non-Office apps that I tried will let you save a file with the same name in the same location that Office won’t.
A couple of other odd problems…
- Explorer won’t let you rename an existing file to something longer than the allowed path name length. It won’t give you an error; it will just stop typing when you hit the limit.
- If you have an existing file that was synced from SharePoint or created with a non-Office application, such as Notepad, so that it exceeds the maximum path name limit, you won’t be able to rename it unless you shorten the name to below the limit. You wont get an error; Explorer just won’t save your change.
I am aware of five possible solutions to the problem of synced SharePoint files exceeding Windows’ maximum path name length. I have seen articles claiming that you can change the LongPathsEnabled value to 1 at HKLM\SYSTEM\CurrentControlSet\Control\FileSystem, but that hasn’t worked for me.
Solution 1: Save to Sites
The simplest solution, by far, is to save the document directly to SharePoint rather than to Windows Explorer. In the Save As (or Save a Copy) dialog box, don’t select “This PC” or “Browse”. Select “Sites – Your Organization” from the available options. You will then be able to select from a list of your Frequently used and Followed SharePoint sites, from which you can browse to the correct location and save your document.
The file will appear in Windows Explorer if you have the location synced to the OneDrive client, but it will appear with a white cloud icon instead of the green check icon (see image at right), indicating that it resides only in the cloud.
Solution 2: Shorten folder and file names
It might seem like a no-brainer solution simply to rename folders and files so that the full path length is shorter, but users can be surprisingly resistant to changing the way that they operate. Sometimes they even have a good reason for not going this route.
Solution 3: Map a Drive
You can map a drive to a local path using the subst command.
C:\Users\jay.carper>subst w: "C:\Users\jay.carper\My Organization\My Team - This is my long private channel name - This is my long private channel name\This is my really long folder name\This is my really long subfolder name\Yet another really long folder name\"
You can now access the path using the W drive mapping. There are two drawbacks to this method, one major, one minor.
The minor drawback is that when you browse the mapped drive in Windows File Explorer, you will not see the OneDrive sync status column.
The major drawback is that the drive mapping will not be persistent across user sessions. When you log out, your drive mapping will disappear. If you want it to be there every time you log into Windows, you’ll have to write a logon script to map it every time.
I’m not certain, but I suspect this might also break Office 365’s multi-edit functionality.
Solution 4: Sync a Subfolder
If you don’t need to access every subfolder of a SharePoint document library frequently, you can remove the sync to the full library and instead sync only the subfolders that you do need. So instead of syncing the entire “My Private Channel” folder from the “My Team – My Private Channel” SharePoint site, you can drill down to the “My Private Channel\Top Folder\Subfolder\Sub-Subfolder” and initiate the sync from there.
This doesn’t work as well if you need to access files in Subfolder and in Sub-Subfolder, because you can’t sync both locations separately. That would create duplicate file structures with “Subfolder\Sub-Subfolder” in the Subfolder sync and “Sub-Subfolder” in the Sub-Subfolder sync. If you think it’s confusing in this article, imagine how confusing it would get when you delete a file in one place, thinking you already had it saved somewhere else and then discover a month later that it’s missing in the “somewhere else” too. To avoid that scenario, Microsoft won’t let you sync a parent folder and its child folder separately. You need to create the sync connection at the higher (lower) point in the tree so that the one connection includes both the parent and child subfolders.
Solution 5: Rename SharePoint Site
The Windows file structure for data synced from a SharePoint site is determined, in part, by the SharePoint site name. If the site is named “My Team of Super Coworkers”, then when you create the sync connection, the OneDrive client will create a folder called “C:\Users\John.Doe\My Organization\My Team of Super Coworkers” and put all the files there.
If the site is associated with a Teams private channel, this compounds the problem, because the site is named for both the Team and the Private Channel, and then document library within the Team is also named for the Private Channel. The SharePoint site for a private channel is named “My Team of Super Coworkers – My Private Channel”.
When you initiate the sync, OneDrive combines the name of the site and the folder you are syncing to get something like “C:\Users\John.Doe\My Organization\My Team of Super Coworkers – My Private Channel – My Private Channel“. This seems to me to have been a terribly shortsighted decision by someone at Microsoft, and I hope they fix it soon, but for now, we just have to deal with it.
You can shorten this path to the synced files in Windows by renaming the SharePoint site from the long, default name. If you are syncing a standard channel of a Team and your Team name isn’t long, then this probably won’t do much for you. However, if it’s a private channel of a Team, it could be a significant character savings due to the doubling of the channel name in the Windows folder name.
Here’s how to rename your SharePoint site and take advantage of the shorter name in Windows:
Step One: Open the SharePoint Site in a Browser
If the site is associated with a Microsoft Team, you can use the Open in SharePoint link in the Teams app. Otherwise, you can access your organization’s SharePoint sites using the SharePoint app at https://portal.office365.com.
Step Two: Edit the Site Name
Click on the gear icon at the top right of the SharePoint site and select Site Information from the dropdown menu.
Edit the site name field with a shorter name and click Save. I recommend using something that still uniquely identifies the site. Reload the site to see the new name in the top left corner. (See the small image to the right.)
Step Three: Stop Syncing the Site to Your Computer
If you are already syncing the SharePoint site to your computer using your OneDrive client, you’ll need to stop the sync and remove the downloaded files. Make sure you get the order of operations correct. Stop the sync first, then delete any downloaded files.
Right click on the OneDrive icon in the system tray, open the settings, and click on “Stop sync” next to the name of the site.
In Windows File Explorer, browse to your Organization’s site collection. In the image below, that’s the collection with the icon that looks like two office buildings. Once you’re there, find the folder that matches the old name of your SharePoint site and that is missing the OneDrive sync status icon in the Status column.
Delete the old sync folder. Make sure it doesn’t have a sync status icon in the Status column! See the folder with the red circle over the Status column in the image above. You wouldn’t want to delete the wrong folder and delete a bunch of files from the cloud instead of just your hard drive.
Step Four: Re-Sync the SharePoint Site
Open the SharePoint site in a web browser again, navigate to the folder you want to sync, and click the Sync icon in the toolbar at the top of the folder and file window.
The site will reconnect to your OneDrive client, which will create a new sync folder under your Organization site collection in Windows Explorer, but this time, with the new, shorter name.
Wait for the synchronization process to complete, and then test it out by creating some new folders and files. Experiment a bit to see what your new limit is. Unfortunately, this method will give you more characters to work with because it shortens the overall path length for files, but it won’t change that 260 character limit.
I recommend trying to keep folder and file names to 20 characters or less as a general rule. That’s usually plenty of characters to give every folder and file a unique and descriptive name and will help you avoid this problem in the long run.
Hopefully, Microsoft will fix this limitation and give us 1000 characters to work with. Why not 32 million? It’s going to happen eventually anyway. Might as well get ahead of the curve now, right, Microsoft?