GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Honor `-Recurse` when `Get-ChildItem` uses `-Name` by daxian-dbw · Pull Request #28078 · PowerShell/PowerShell

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Sep 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR Summary

Fix Get-ChildItem -Name so recursive searches with a wildcard or exact leaf path enumerate matching files in subdirectories. The name-only path now reuses the recursive path normalization already used by regular item enumeration.

Add regression coverage for wildcard and exact leaf paths, including searches relative to the current directory and -Depth 0 behavior.

PR Context

Get-ChildItem *.md -Recurse -File -Name previously expanded *.md only in the starting directory. The resolved files are not containers, so recursive name enumeration never received a directory root and did not visit subdirectories.

Validation:

  • Debug build with regenerated resources
  • Get-ChildItem.Tests.ps1: 31 passed
  • FileSystemProviderExtended.Tests.ps1: 78 passed

Before the fix:

## PWD is Q:\yard
PS:35> dir *.md -Recurse -File

    Directory: Q:\yard\delme

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           9/23/2026 12:47 PM              0 delme.md

    Directory: Q:\yard

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           9/21/2026 11:57 AM           1402 note.md

PS:36> dir *.md -Recurse -File -Name
note.md

After the fix:

PS Q:\yard> dir *.md -Recurse -File -Name
note.md
delme\delme.md

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready for Review when it is ready to merge.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed:
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw
Fix 'Get-ChildItem -Name' to not suppress '-Recurse'
50690b6
Copilot AI lite review requested due to automatic review settings September 24, 2026 04:02
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a review from a team as a code owner September 24, 2026 04:02
@azure-pipelines

azure-pipelines Bot commented Sep 24, 2026

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of Dongbo Wang (daxian-dbw) September 24, 2026 04:03
View session

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 24, 2026
@daxian-dbw Dongbo Wang (daxian-dbw) changed the title Honor -Recurse when Get-ChildItem uses -Name Honor -Recurse when Get-ChildItem uses -Name Sep 24, 2026
@daxian-dbw
Preserve wildcard filters in public GetNames API
ecb9924
Co-authored-by: Copilot App <[email protected]>
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a lite review from Copilot September 24, 2026 16:54
Copilot started reviewing on behalf of Dongbo Wang (daxian-dbw) September 24, 2026 16:55
View session
daxian-dbw
Dongbo Wang (daxian-dbw) commented Sep 24, 2026
View reviewed changes
Comment thread src/System.Management.Automation/engine/SessionStateContainer.cs
{
// If we're recursing, do some path fixups to match user
// expectations, but only if the last part is a file and not a directory:
if (recurse && !path.EndsWith(Path.DirectorySeparatorChar) && !path.EndsWith(Path.AltDirectorySeparatorChar))

@daxian-dbw Dongbo Wang (daxian-dbw) Sep 24, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed code here was actually moved to the NormalizePathForChildItemRecursion method below, with no change at all.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Dongbo Wang (daxian-dbw) requested a lite review from Copilot September 25, 2026 00:45
Copilot started reviewing on behalf of Dongbo Wang (daxian-dbw) September 25, 2026 00:46
View session

This comment was marked as off-topic.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Dongbo Wang (daxian-dbw) force-pushed the dir-name-recurse branch from 6328501 to ecb9924 Compare September 25, 2026 03:53
@iSazonov

Ilya (iSazonov) commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Is your description in "Before the fix:" correct? It seems #9014 is not fixed jet. Also PowerShell Committee conclusion was to reject the change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Sep 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

This PR will fix #9014:

PS Q:\yard> Get-ChildItem -Path *.md -Recurse -Name
note.md
.abc\abc.md
delme\delme.md
tmp\hello\world\world.md

PS Q:\> Get-ChildItem -Path Q:\yard\*.md -Recurse -Name
note.md
.abc\abc.md
delme\delme.md
tmp\hello\world\world.md

I didn't know that issue and thanks for pointing me to it.

I disagree with the WG conclusion. It's hard to imagine someone would depend on this breaking behavior -- they specify -Recurse but Get-ChildItem doesn't traverse the directories. I think if there is anyone who is doing that today, it's very likely they didn't know it's broken and assumed it works the way they expected (same as dir -path ... -Recursive but just output the names).

Note that Get-ChildItem -Path . -Include *.md -Recurse -Name works today, and that makes it hard to justify the -Name behavior except for accepting that it's broken. This kind of inconsistency impacts how AI can write high-quality PowerShell commands when using PowerShell as the shell-invocation tool on Windows.

MartinGC94 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Oct 3, 2026
@microsoft-github-policy-service

microsoft-github-policy-service Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

SeeminglyScience
Patrick Meinecke (SeeminglyScience) approved these changes Oct 9, 2026
View reviewed changes
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 5d871eb into PowerShell:master Oct 9, 2026
69 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the dir-name-recurse branch October 9, 2026 17:21
@daxian-dbw Dongbo Wang (daxian-dbw) removed the Review - Needed The PR is being reviewed label Oct 9, 2026
@BrucePay

Bruce Payette (BrucePay) commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

This is a breaking change but is not marked as such. It will break patterns i use like renaming a directory to "directory.old", "directory.old.old" etc. It should at least be documented as a breaking change in the release notes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@SeeminglyScience Patrick Meinecke (SeeminglyScience) SeeminglyScience approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@daxian-dbw @iSazonov @BrucePay @SeeminglyScience
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.