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

Status : 

  External<br /><br />
		This item may be valid but belongs to an external system out of the direct control of this product team.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 467904 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 6/17/2009 10:38:58 AM
Access Restriction Public


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 *
PS:> gci

however when the filter, path and recurse parameters are used together only the files matching in the top level directory are returned.
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
are totally different when it comes to recursion


you are both correct as not.

When one uses this

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

this cmdlet will call the providers GetChildNames method

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

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>
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.