Forum Discussion
Sites with long file path length
I have a big problem to solve with SharePoint online Teams sites where data was migrated from On-Prem file shares and there are more items with a long file path length than we are able to fix. In some directories, it has gotten better but employees didn't listen to us when we told them to start creating less nested folders, shorter file and folder name and to try and fix older directories. In the beginning around 2 years ago, we migrated everything and turned on OneDrive sync and found out quickly how that wasn't going to work for one department, so we then told them to work out of the browser which seemed to solve the problem. Well, not everyone kept working from only the browser and more and more people continued to get OneDrive sync issues.
Now I have ran some reports to get the actual file path length for some of the sites. For the biggest site, I show the largest file path length at 397, and I figured 220 would give a good starting point to have OneDrive successfully sync without errors given that OneDrive and File Explorer will add extra characters in the path. Starting at 220 characters, there are more than 61,000 affected files with a path ranging from 220 - 397, and more than 107,000 starting at 200 characters.
The first problem to solve is to get the department to stop naming files in this way and stop creating all the nested folders. They need to establish a better naming convention.
The second problem to solve is fixing as many of these as possible, but with this many items to correct it seems impossible. Has anyone worked on a SP online site to programmatically fix something like this to reduce the path length? Even trying this with a script sounds impossible, but there has to be something that can be done to help? Right??
1 Reply
- virendrakSteel Contributor
At this point, this isn't really a SharePoint problem. It's a file management problem that was carried over from the old file shares. With 60,000+ files affected, nobody is going to fix this manually.
The best approach is to stop creating new long paths by enforcing a naming convention and reducing folder nesting. For the existing content, I'd focus on shortening and reorganizing folders rather than renaming individual files. A single folder rename can reduce the path length for thousands of files underneath it.
PowerShell (PnP PowerShell) can help identify the worst offenders and automate some of the cleanup, but the biggest gains usually come from fixing the folder structure, not the files themselves. If browser access is working well for this department, it may also be worth reconsidering whether OneDrive sync is appropriate for the entire library.
I'd prioritize reporting on:
- Longest folder names
- Deepest folder structures
- Number of files under each folder
Then focus on the top-level folders with the greatest impact. Renaming or restructuring a handful of long, heavily used folders can shorten the paths for thousands of files in one go.
So yes, something can definitely be done, but I'd tackle it strategically rather than trying to fix 61,000 files one by one. That's a governance and cleanup project, not a manual remediation exercise.