Author Posts

August 27, 2018 at 5:44 pm


I am trying to find a PowerShell script that will produce a list of all files\folders where the total path is more than 260 characters.

I see the following but it doesn't seem to work.
Dir d:\data\FolderName Get-ChildItem | Where-Object {$_.FullName.Length -gt 260}
I also tried Get-ChildItem | Where-Object {$_.FullName.Length -gt 260}  from but that does work.

Can someone let me know what I am missing?




August 27, 2018 at 8:59 pm

With recent version of Windows, you can set a registry change to deal with long file names.

August 27, 2018 at 10:03 pm


Get-ChildItem -Recurse -Force -ErrorAction SilentlyContinue | 
  Where-Object {$_.FullName.Length -gt 260}

August 28, 2018 at 4:17 pm

Hi Js, Sorry that doesn't appear to work.

August 28, 2018 at 4:22 pm


When you say it doesn't work, what do you mean?  Is it giving you an error?  If so, can you please post.  If it is providing incorrect results can you elaborate?


August 28, 2018 at 5:44 pm

Using that script provides no results.  It doesn't error out but nothing happens.

August 28, 2018 at 5:47 pm

If you want to search from the top folder on the c drive, c:\, it would be (or cd to it first):

Get-ChildItem C:\ -Recurse -Force -ErrorAction SilentlyContinue | 
  Where-Object {$_.FullName.Length -gt 260}

August 30, 2018 at 12:21 pm

Sorry I am really a beginner.  I modified your command  to try to get a list of files in a directory that exceed 260 characters as follows after selecting: cd d:\
Get-ChildItem D:\Data\”Communications Team” -Recurse -Force -ErrorAction SilentlyContinue |  Where-Object {$_.FullName.Length -gt 260}
After a few seconds the PS D:\> prompt returns but doesn't do anything or produce any results.  What am I missing?


August 30, 2018 at 1:33 pm

Get-ChildItem isn't coded to allow for longer paths, from what I recall. So it won't find anything.

What you can do is grab the NTFSSecurity module (Import-Module NTFSSecurity), which contains a Get-ChildItem2 cmdlet. It works the same as Get-ChildItem, but utilises a third party DLL to handle longer paths as well.

August 30, 2018 at 9:50 pm

It works for me. What if you take out the "-erroraction silentlycontinue" option? Is there an error message?

    Directory: C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsq

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       10/29/2017   9:09 PM          53903 installsqlstatetemplate.sql

    Directory: C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_personali

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       10/29/2017   9:12 PM           7489 uninstallpersonalization.sql

    Directory: C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_uninstall

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       10/29/2017   9:18 PM          10195 uninstallpersistsqlstate.sql

September 4, 2018 at 2:26 pm

Hi JS,

Unfortunately, I get the following error.

PS D:\data> Get-ChildItem ”Communications Team” -Recurse |  Where-Object {$_.FullName.Length -gt 260}
Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than
260 characters, and the directory name must be less than 248 characters.
At line:1 char:1
+ Get-ChildItem ”Communications Team” -Recurse |  Where-Object {$_.FullName.Length ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ReadError: (D:\data\ Photos Files:String) [Get-ChildItem], PathTooLongExcept
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

September 7, 2018 at 1:48 pm

Have you tried PS 6? There's something about long pathnames that might get backported to PS 5.

There might be a long pathname syntax?

"When calling Windows native API to determine if an item exists, ensure the path is prepended with \\?\ to allow for paths > 260 characters."


Try this:

Get-ChildItem -literalpath \\?\C:\ -Recurse | 
  Where-Object {$_.FullName.Length -gt 260}


Btw what version of powershell do you have? I don't have any problems in 5.1.16299.611.