Update: I added a small script below to create a folder structure in a tenant so that you can test the new limit

Yesterday, Microsoft announced another small but great change to SharePoint Online and OneDrive: in previous versions of SharePoint you were limited to a maximum path length of 256 characters. This meant that if you had a very deep folder structure, potentially also with long file or folder names, you would at some point hit that limit and not be able to add any files/folders which would have a total path length of more than 256 characters. In SharePoint Online and OneDrive, this limit has now been increased to 400!

While a lot of people advise to move away from folders and towards a metadata-driven architecture, the reality is that the majority of a company’s information is organised with folders. Lots and lots of folders. Which, on your local hard drive or a shared drive, are often organised in a tree-like structure with multiple levels, and thus also potentially exceeding the path length limit.

But, this may cause problems during migrations to SharePoint Online. I’ve seen it during a couple of projects I did recently which migrated content to SharePoint Online – and while more than 99.9% of the content was able to move without issues, there were still some files that were impacted by this limit. Path length in the source environment may have been still below the limit, but as the content was restructured (e.g. it was moved to another subsite with a longer path), the overall length increased and the content could not get migrated. The only option was to reduce the path length, for example by reorganising the folder structure, or renaming files/folders.

Coming back to SharePoint Online and OneDrive: this new limit should be available to everyone straight away! I wrote a small PowerShell script to create a simple folder hierarchy, and was able to go beyond the 256 characters and hit the 400 limit:

And here’s the error shown when you try to create a folder in the UI:

One thing I noticed, however, is that the explanation given by Microsoft on which parts of the file URL are actually part of the path seems to be not quite correct. In my test setup, I managed to successfully create a path of 430 characters, 431 failed. After a quick check I saw that my protocal and server name came to a total of 30 characters – so, I asked on the official announcement for a clarification. But either way, it should be quite rare to run into the 400 character limit, and it’s great to see that Microsoft is finally addressing an issue that has been around for a long period of time.

Update: Here is the script that I used. It will run into a limit and you’ll get an error similar to the screenshot further above. Also, please note that the script creates a library, but does not delete it.

#replace with your own demo site in your own tenant
$url = "https://mytenant.sharepoint.com/sites/demo"
#modify the following two variables if required
$libName = "MaxPathTest"
$folderName = "012345678901234567890123456789"

$cred = Get-Credential
write-host "Connecting to $($url)"
Connect-PnPOnline -Url $url -Credentials $cred
write-host "Creating library $($libName)"
New-PnPList -Title $libName -Template DocumentLibrary

$folder = $libName
do {
	$pathLength = $url.Length + 1 + $folder.Length + 1 + $folderName.Length
	write-host "Trying path length of $($pathLength)"
	Add-PnPFolder -Name $folderName -Folder $folder
	$folder = $folder+"/"+$folderName	
} while ($pathLength -le 500)

18 thoughts on “Increased Path Length for Files in SharePoint Online and OneDrive”

    1. Hi, I think it’s the same details as in the techcommunity announcement. Still unsure about the actual definition of what goes into the path. But as mentioned, 400 is quite a lot of characters, should make it a very rare occurrence to run into this limit

      1. Rene… I think you are correct. My protocol and server name came to 34 chars and it let me increase until I hit 434. So I think it is similar to the old 256 # where the protocol and server name don’t count.

  1. Do we need to send a request to Microsoft to increase the MAXPATH size or this can be done by global admin?

  2. By any chance anyone have a script to list down all the files and folders that exceeded the maxpath limit and export it as a text file?

    I’ve seen some powershell scripts however it seems to be directed to on-premise sharepoint instead of Sharepoint Online.

    Am trying to save a sharepoint site as a template however keep getting path too long error after fixing file after file as the error only indicated 1 affected file each time the command was ran.

    Would like to batch list them so that I can fix them before attempting to run the save as template command again.

    1. Hi Asri,

      the following should get you started. It will get all items from a specified library (note, there may be issues with libraries with more than 5,000 items) and check the path length for each item. If the length is greater than 400, it will output the name:

      #replace with your own demo site in your own tenant
      $url = “https://mysite.sharepoint.com/sites/demo”
      #modify the following two variables if required
      $libName = “mylibname”

      $cred = Get-Credential
      write-host “Connecting to $($url)”
      Connect-PnPOnline -Url $url -Credentials $cred

      $list = Get-PnPList | where {$_.Title -eq $libName}
      $items = Get-PnPListItem -List $list
      foreach($item in $items) {
      Get-PnPProperty -ClientObject $item -Property File,Folder
      $fullpath = $url
      #folder
      if(($item.File.Name -eq $null) -and ($item.Folder.Name -ne $null)) {

      $fullpath += $item.Folder.ServerRelativeUrl
      }
      if($item.File.Name -ne $null) {
      $fullpath += $item.File.ServerRelativeUrl
      }
      if($fullpath.Length -ge 400) {
      write-host $fullpath
      }
      }

  3. How can we delete a folder at once which is having files exceeding the character limit . I do not have time to sit and delete / rename one file at a time .

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.