I want to find files recursively, and for that I am using

> gci -name -filter *.py -r

Option -name gives only the file name, to get one line per item found, as required. But the items that I get as output show only the relative path, e.g.


(the current dir is C:\python) while a similar command in cmd.exe

> where /r . *.py



as wanted.

Is there any way of getting this with gci?

I would like to minimize piping/greping with regex/the like.

2 Answers 2


I'm not sure why you're averse to piping, since it is arguably the most imporant feature of PowerShell, but I would leave out the -name parameter. Then, use Select-Object (alias, select) to get the FullName of the FileInfo object, and use the -expand switch to output only the string value of the FullName property. If you want to keep it short, you can also leave out -filter and add '.', since the second positional parameter is -Filter.

gci . *.py -r| select -exp fullname

Or use Foreach-Object (alias, % or foreach), and output the FullName.

gci . *.py -r| % {$_.FullName}
  • 1
    gci -filter *.py -r| select -expand fullname is probably cleaner than your second option which is probably what OP's looking for.
    – zdan
    Dec 18, 2013 at 23:51
  • Yes, I think you're right @zdan. I'll add that switch to the first example.
    – Rynant
    Dec 19, 2013 at 14:54
  • Both options work ok. Dec 20, 2013 at 14:45

To avoid using piping, you can use the following:

(gci -filter *.py -recurse).FullName
  • This didn't work, at the same prompt where both options given by Rynant work. Dec 20, 2013 at 14:42
  • @sancho.s, the answer should work for PowerShell v3 and up.
    – Rynant
    Dec 20, 2013 at 15:15
  • @Rynant - That's probably the reason, I think I have v2 (as per >$PSVersionTable.psversion) Dec 20, 2013 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.