if no proper acceptation or training is provided to users, users will create a lot of folders in folders and very long file names without realizing that Sharepoint/Onedrive has it's own limits and so does Windows.
Result is that files synced in OneDrive from a Sharepoint Site will not open due to the lenght of it exceeding the 255 character limit.
Microsoft has a way to increase the limit by editing the registry, but I found that solution doesn't always work.
The best solution is to tell users to reduce the amount of characters in a filename and reduce the nesting of folders.
To identify which files exceed the 255 character limit you can run this command:
$onedrive = $env:OneDriveCommercial
Get-Date >> $onedrive\onedrive.txt
Get-ChildItem $onedrive -Recurse | ForEach-Object {
if($_.FullName.Length -gt 260){
"{0} = {1}" -f $_.FullName, $_.FullName.Length >> $onedrive\onedrive.txt
"{0} = {1}" -f $_.FullName, $_.FullName.Length
}
}
Change $env:OneDriveCommercial to $env:OneDrive if you want to check the folders that are synced to Sharepoint sites. OneDriveCommercial is for the user personal onedrive.