Skip to content

NTFS: Remove-Item cannot delete Directories with long names which New-Item can create #3859

@schittli

Description

@schittli

Good evening

of course, anno 2017 it's annoying to still have to fight with 260 character limits and that powershell is not using the unicode File API. (Win10 LongPathsEnabled is set to 1). Anyway.

Remove-Item cannot delete a directory which was created by Net-Item, it reports that the path is "too long".

Steps to reproduce

PS C:\temp> # Create a Directory
PS C:\temp> $dirname = 'c:\Temp\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345'

PS C:\temp> New-Item -ItemType Directory -Force -Path $dirname
    Directory: C:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       25.05.2017     00:52                123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345

PS C:\temp> # Delete Directory
PS C:\temp> Remove-Item -Force -Recurse -Path $dirname
Remove-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.
At line:1 char:1
+ Remove-Item -Force -Recurse -Path $dirname
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Temp\1234567...123456789012345:String) [Remove-Item], PathTooLongException
    + FullyQualifiedErrorId : RemoveItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand

Expected behavior

We expect, that PowerShell suports some 1000s characters.
But at least, that Remove-Item can delete Items which were created by New-Item.

Actual behavior

Remove-Item can not delete Items with long path names which were created by New-Item.

Environment data

> $PSVersionTable
PS C:\temp> $PSVersionTable

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions