Change Get-ChildItem to treat trailing slash in path as indicating a directory when used with -Recurse (#17704)

This commit is contained in:
Steve Lee
2022-07-21 09:39:11 +05:00
committed by GitHub
parent 031fa93b4c
commit 3efa28162e
3 changed files with 21 additions and 5 deletions
@@ -217,6 +217,17 @@ Describe "Get-ChildItem" -Tags "CI" {
It "Should list the folder present when path length equal to MAX_PATH" {
(Get-ChildItem -Path TestDrive:\$item_I -Recurse -Force).Name.Length | Should -BeGreaterThan 0
}
It 'Trailing slash for -Path should treat it as a folder only when used with -recurse' {
$foo = New-Item -ItemType Directory -Path TestDrive:\foo
$foo2 = New-Item -ItemType Directory -Path TestDrive:\foo\foo
$bar = New-Item -ItemType File -Path TestDrive:\foo\bar
$bar2 = New-Item -ItemType File -Path TestDrive:\foo\foo\bar
{ Get-ChildItem -Path testdrive:/foo/bar/ -Recurse -ErrorAction Stop } | Should -Throw -ErrorId 'ItemNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand'
$barFiles = Get-ChildItem -Path testdrive:/foo/bar -Recurse
$barFiles.Count | Should -Be 2
}
}
Context 'Env: Provider' {