Skip to content

NTFS: Rename-Item: does not support 255 Characters #3862

@schittli

Description

@schittli

On NTFS, Rename-Item just supports 254 characters (per path-segment, I guess).
If we try to rename a Direcotry with 255 characters, Rename-Item throws an Exception (even if the underlying APS probably does not :-() (Why is PowerShell doing the same tests which the underlying API is doing anyway? It would be less error-prone to just use the well tested API)

The same Problem exists in Remove-Item: it throws an exception if it has to handle 255 characters.

Steps to reproduce

PS C:\temp> New-Item -Type Directory -Path "c:\Temp\$('a' * 255)"
    Directory: C:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       25.05.2017     12:44                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


PS C:\temp> Rename-Item -Path "c:\Temp\$('a' * 255)" -NewName "c:\Temp\abc"
Rename-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
+ Rename-Item -Path "c:\Temp\$('a' * 255)" -NewName "c:\Temp\abc"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Temp\aaaaaaa...aaaaaaaaaaaaaaa:String) [Rename-Item], PathTooLongException
    + FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand

PS C:\temp>

Btw: 254 Characters are supported:

PS C:\temp> New-Item -Type Directory -Path "c:\Temp\$('a' * 254)"
    Directory: C:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       25.05.2017     12:46                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

PS C:\temp> Rename-Item -Path "c:\Temp\$('a' * 254)" -NewName "c:\Temp\abc"
PS C:\temp> # Rename-Item worked perfectly

Expected behavior

Because 255 Characters are supported by NTFS, PowerShell should support 255 Characters, too.

Actual behavior

PowerShell just supports 254 Characters (per path segment, I guess)

Environment data

> $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-BugIssue has been identified as a bug in the productResolution-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