Skip to content

PowerShell extended property BaseName for DirectoryInfo is inconsistent when there is an extension #21553

Closed
@Hashbrown777

Description

@Hashbrown777

Prerequisites

Steps to reproduce

This occurs on both windows and linux, starting at v5 all the way through to now.
<#System.IO.FileInfo#> | %{ $_.BaseName + $_.Extension } should always be equivalent to <#System.IO.FileInfo#>.Name
For gci -File this holds true.
For gci -Directory although pwsh correctly has .BaseName always match .Name (folders cannot have extensions..), .Extension incorrectly matches .Name -replace '^.*?(?=\.[^.]*$|$)','' instead of always returning ""

Expected behavior

PS> (New-Item -Type Directory -Name 'bob.steve 123_456[yoyo]').Extension

PS>

Actual behavior

PS> (New-Item -Type Directory -Name 'bob.steve 123_456[yoyo]').Extension
.steve 123_456[yoyo]
PS>

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Fedora Remix for WSL
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignThe reported behavior is by design.WG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions