Author Posts

August 27, 2018 at 5:44 pm

Hello,

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.
  https://www.powershellmagazine.com/2012/07/24/jaap-brassers-favorite-powershell-tips-and-tricks/
 
Dir d:\data\FolderName Get-ChildItem | Where-Object {$_.FullName.Length -gt 260}
I also tried Get-ChildItem | Where-Object {$_.FullName.Length -gt 260}  from https://stackoverflow.com/questions/12697259/how-do-i-find-files-with-a-path-length-greater-than-260-characters-in-windows but that does work.

Can someone let me know what I am missing?

thanks,

Roger

 

August 27, 2018 at 8:59 pm

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

https://blogs.msdn.microsoft.com/jeremykuhne/2016/07/30/net-4-6-2-and-long-paths-on-windows-10

August 27, 2018 at 10:03 pm

This?

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

Roger,

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
    lstatetemp_b03f5f7f11d50a3a_10.0.17134.1_none_ff11cd80956b65aa


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
    zation_sql_b03f5f7f11d50a3a_10.0.17134.1_none_bdf33e156afb2609


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
    persistsql_b03f5f7f11d50a3a_10.0.17134.1_none_53b314e56d2c48b4


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\Communi...al Photos Files:String) [Get-ChildItem], PathTooLongExcept
ion
+ 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. https://github.com/PowerShell/PowerShell/pull/3960

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."

EDIT:

Try this:

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

reference: https://stackoverflow.com/questions/46308030/handling-path-too-long-exception-with-new-psdrive/46309524

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