How to Fix Long Path Names in Windows for Synced SharePoint Files or OneDrive

When syncing your OneDrive for Business with the Microsoft OneDrive sync tool or SharePoint “onedrive.exe” you may receive an error “We Can’t Sync This Item Because The Path Is Too Long”.

OneDrive for Business has a maximum URL path length of 260 characters. If the file you have created in your locally synced OneDrive for Business folder would exceed the 260 URL path length limitation then the sync tool will show this error.

 

To resolve the long path issue and sync your file you will need to rename it to reduce the length of the file name to be within the 260 character URL length limit of OneDrive for Business. The dialog shown by the onedrive.exe sync tool advises how many characters need to be removed from the file path for it to sync.

If renaming the file is not an option an alternative is to rename the folder that the file resides to reduce its length. Or you can move the file to a different folder that has a shorter path length.

When you have hundreds of even thousands of files with long paths it may become overwhelming trying to fix up them up so you can get your files synced to OneDrive for Business. You may find a tool helpful. Files To Go, our file migration tool for Office 365, automatically identifies files with paths that are too long and skips them so that your migration to OneDrive for Business will not be interrupted.

 

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

Solutions

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.

 

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?

Leave a Comment

Your email address will not be published. Required fields are marked *