This topic contains 10 replies, has 7 voices, and was last updated by
October 19, 2018 at 9:08 am #114559
Powershell is getting better and better, but the limitations of only 260 character with Get-Childitem is hilarious when i see the comment at the "Topic Title" (Maximum Length: 80)
Am guessing there is a good reason, for the limitation..
Is there some workaround i can build into my script so it wil go to the path where/if error occurs and restart the scan with the same parameters?
October 19, 2018 at 9:15 am #114574ModeratorPoints: 204Rank: Participant
The 260 character limit for paths is actually part of the Windows API.
If you're running on anything more recent than Windows 10 version 1607, you can opt-in to a new behavior that does allow paths longer than 260 chars. Taken from "Naming a File":
> A registry key allows you to enable or disable the new long path behavior. To enable long path behavior set the registry key at `HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD)`
The article also notes that you can set it via GPO, and that you may need a reboot to fully realize the benefits.
Having said that, if you're relying on this feature and then publish scripts / functions / modules, it may be a fun issue to diagnose for unwary users!
October 19, 2018 at 10:05 am #114585
Am using Windows Server 2012 R2. I want to achieve to get all hidden files from a fileserver. but i get the limitation error
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
I gonna try to grep the error and use the path in the error as new starting point to execute the command again
October 19, 2018 at 11:27 am #114597ParticipantPoints: 1,375Rank: Community Hero
You could use robocopy to "scan" the folders with the option "/L", log the result to a file and parse this file with Powershell ... that's how I did it a while ago. 😉
October 19, 2018 at 11:58 am #114609
What version of PS do you have? Does using 5.1 or 6 make a difference? Or try the \\?\C:\ syntax. Related thread: https://powershell.org/forums/topic/script-to-find-long-path-names/
October 19, 2018 at 2:10 pm #114624
It is version 4.0.. 🙁
October 19, 2018 at 3:54 pm #114693ParticipantPoints: 380Rank: Contributor
You can use 3:rd party libraries.
Wrote a couple of blog posts about QuickIO.Net here:
It was over a year ago since I wrote the last blog post so I can't remember if the file attributes get captured.
QuickIO is no longer developed as far as I know, there are other libraries but can't remember the names.
October 19, 2018 at 4:55 pm #114720
Does something like this work? https://stackoverflow.com/questions/46308030/handling-path-too-long-exception-with-new-psdrive/46309524
get-childitem -literalpath \\?\C:\ -recurse
October 24, 2018 at 8:35 pm #118690ParticipantPoints: 117Rank: Participant
This is one of the use cases I use PowerShell Core for!
Fixed PowerShell Core to allow use of paths that are more than 260 characters long. (#3960)
October 24, 2018 at 10:03 pm #118731ParticipantPoints: 65Rank: Member
This is the related Github issue that John's Microsoft doc alludes to. Great find, if it's acceptable to get this running on OP's server.
October 24, 2018 at 10:08 pm #118732
PS 5.1 has the same problem. Have you tried putting '\\?\' in front of the path? I happen to have a file whose path is 265 characters. It will say "Cannot find path" without the prefix.
PS C:\> $a = ls \\?\C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5f7f11d50a3a_10.0.17134.1_none_ff11cd80956b65aa\installsqlstatetemplate.sql PS C:\> $a Directory: \\?\C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5 f7f11d50a3a_10.0.17134.1_none_ff11cd80956b65aa Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/29/2017 9:09 PM 53903 installsqlstatetemplate.sql PS C:\> $a.tostring() \\?\C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5f7f11d50a3a_10.0.17134.1_none_ff11cd80956b65aa\installsqlstatetemplate.sql PS C:\> $a.FullName.length 265 PS C:\> ls C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5f7f11d50a3a_10.0.17134.1_none_ff11cd80956b65aa\installsqlstatetemplate.sql ls : Cannot find path 'C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Window s-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5f7f11d50a3a_10.0.17134.1_non e_ff11cd80956b65aa\installsqlstatetemplate.sql' because it does not exist. At line:1 char:1 + ls C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\WINDOWS\Soft...atetemplate.sql:String) [Get-ChildItem], ItemNotFound Exception + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Confirmed that it works more easily in PS 6, which is portable.
PS C:\> pwsh PowerShell 6.1.0 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/pscore6-docs Type 'help' to get help. PS C:\> ls C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3-OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5f7f11d50a3a_10.0.17134.1_none_ff11cd80956b65aa\installsqlstatetemplate.sql Directory: C:\WINDOWS\SoftwareDistribution\Download\ae84ea9d8e2d5b57697fdac2a81468b1\amd64_Microsoft-Windows-NetFx3 -OnDemand-Package~~AMD64~~10.0.17134.1\amd64_netfx-aspnet_installsqlstatetemp_b03f5f7f11d50a3a_10.0.17134.1_none_ff 11cd80956b65aa Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/29/2017 9:09 PM 53903 installsqlstatetemplate.sql
The topic ‘Get-Childitem Limitation of 260 characters. Is this the year 2018?’ is closed to new replies.