Home Dashboard Directory Help
Search

Get-ChildItem -Path * -Filter <filter> -Recurse should be all items that match the filter by Bob Landau


Status: 

Closed
 as External Help for as External


3
0
Sign in
to vote
Type: Bug
ID: 467904
Opened: 6/17/2009 10:38:58 AM
Access Restriction: Public
0
Workaround(s)
view
3
User(s) can reproduce this bug

Description

According to the helpfile for Get-ChildItem "-Filter" qualifies the -Path parameter

My claim is that nearly everyone will consider the following two commands identical

PS:> gci *
and
PS:> gci

however when the filter, path and recurse parameters are used together only the files matching in the top level directory are returned.
Details
Sign in to post a comment.
Posted by rbellamy on 12/6/2011 at 9:26 PM
Closing this as external is a cop-out.
Posted by Bob Landau on 6/17/2009 at 12:41 PM
Here is some more details of what I believe to be at best a doc bug explaining that for Powershell unlike other Shells

an empty path
and
*
are totally different when it comes to recursion
===============================================

Paul

you are both correct as not.

When one uses this

Get-ChildItem -Path * -Recurse -Filter <filter>
or
gci * -Recurse -Filter <filter>


this cmdlet will call the providers GetChildNames method

protected virtual void GetChildNames (
    string path,
    ReturnContainers returnContainers <<< This is set to
ReturnMatchingContainers
)

its a no win situation if it were set to ReturnAllContainers then the filter
would be ignored. Set as it is it will not recurse.

If one does this which in my opinion should give the same results

Get-ChildItem -Recurse -Filter <filter>
or
gci -Recurse -Filter <filter>

this cmdlet will call the providers GetChildItems method

protected virtual void GetChildItems (
    string path,
    bool recurse
)

in this case there is a flag so the provider must return everything matching
the filter in all directories.

In either case the cmdlet Get-ChildItem is not implementing the recursion
merely passing on the flag to the provider.

There's not a really good solution. Personally I think GetChildNames should
have had a parameter for recursion so that Get-ChildItems could have passed
this on.

I don't know of another OS which doesn't treat both an empty path and an
asterics as the same exact semantics.

As it stands now I don't know what can be done other than making the
documentation clearly state this. What I would really like to see is the
Powershell group fix/extend (in my opinion) GetFileNames to have an
additional parameter for recursion.

thx
bob
Sign in to post a workaround.