get-childitem -LiteralPath should accept 'Include' or 'Exclude' filter (#5462)

* get-childitem -LiteralPath should accept 'Include' or 'Exclude' filter
This commit is contained in:
Chunqing Chen
2018-03-02 14:34:53 -08:00
committed by Aditya Patwardhan
parent b30a614e5a
commit 502ee8f757
2 changed files with 26 additions and 1 deletions
@@ -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)