mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
get-childitem -LiteralPath should accept 'Include' or 'Exclude' filter (#5462)
* get-childitem -LiteralPath should accept 'Include' or 'Exclude' filter
This commit is contained in:
committed by
Aditya Patwardhan
parent
b30a614e5a
commit
502ee8f757
@@ -1654,7 +1654,25 @@ namespace System.Management.Automation
|
||||
|
||||
ContainerCmdletProvider providerInstance = GetContainerProviderInstance(provider);
|
||||
|
||||
if (path != null && this.ItemExists(providerInstance, path, context))
|
||||
if (
|
||||
(context.Include != null && context.Include.Count > 0) ||
|
||||
(context.Exclude != null && context.Exclude.Count > 0))
|
||||
{
|
||||
// Do the recursion manually so that we can apply the
|
||||
// include and exclude filters
|
||||
int unUsedChildrenNotMatchingFilterCriteria = 0;
|
||||
try
|
||||
{
|
||||
// Temeporary set literal path as false to apply filter
|
||||
context.SuppressWildcardExpansion = false;
|
||||
ProcessPathItems(providerInstance, path, recurse, depth, context, out unUsedChildrenNotMatchingFilterCriteria, ProcessMode.Enumerate);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.SuppressWildcardExpansion = true;
|
||||
}
|
||||
}
|
||||
else if (path != null && this.ItemExists(providerInstance, path, context))
|
||||
{
|
||||
if (IsItemContainer(providerInstance, path, context))
|
||||
{
|
||||
|
||||
@@ -95,6 +95,13 @@ Describe "Get-ChildItem" -Tags "CI" {
|
||||
(Get-ChildItem -Path $TestDrive -Depth 1 -Exclude $item_a).Count | Should Be 5
|
||||
}
|
||||
|
||||
It "Should return items recursively when using 'Include' or 'Exclude' parameters with -LiteralPath" {
|
||||
(Get-ChildItem -LiteralPath $TestDrive -Recurse -Exclude *).Count | Should Be 0
|
||||
(Get-ChildItem -LiteralPath $TestDrive -Recurse -Include *.dll).Count | Should Be (Get-ChildItem $TestDrive -Recurse -Include *.dll).Count
|
||||
(Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Include $item_G).Count | Should Be 1
|
||||
(Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Exclude $item_a).Count | Should Be 5
|
||||
}
|
||||
|
||||
It "get-childitem path wildcard - <title>" -TestCases $PathWildCardTestCases {
|
||||
param($Parameters, $ExpectedCount)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user