Please feel free to provide feedback or file bugs here.

Get-ChildItem -LiteralPath doesn't support long path

Get-ChildItem -LiteralPath doesn't support long path, for example:

Get-ChildItem -LiteralPath 'D:\aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnooooooooooppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxyyyyyyyyyyzzzzzzzzzz.txt'

Which path is longer than 260 bytes, even if the file DO exists in that path.

But `Get-ChildItem` WITHOUT `-LiteralPath` works well with that long-path file.

$PSVersionTable

Name Value
---- -----
PSVersion 5.1.17763.134
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.134
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

5 votes
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

Victor Woo shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...
  • PoshCode commented  ·   ·  Flag as inappropriate

    How did you create the file: ??? With which command/application ???

    D:\aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnooooooooooppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxyyyyyyyyyyzzzzzzzzzz.txt

    I keep getting ERROR :

    New-Item : 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.

    Notepad.exe -----> SaveAs = Error The PATH too long! Try a shorter PATH!

    Could someone plz lend me a lampe so that I may 'lighten' my PATH... :P

  • Karim_Kanoun commented  ·   ·  Flag as inappropriate

    The Powershell module NTFSSecurity can solve your problem, it contain many interesting cmdlets, but also cmdlets like Get-ChildItem2 that can handle paths with up to 32K char.
    It is published in the SCriptCenter, here is the link : https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85
    You wil find a tutorial link to help you use it

Feedback and Knowledge Base