Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to use get-childitem recursively, but only have it return files not directories. The best solution I have just doesn't seem natural:

gci . *.* -rec | where { $_.GetType().Name -eq "FileInfo" }
share|improve this question

3 Answers 3

up vote 32 down vote accepted

Try this:

gci . *.* -rec | where { ! $_.PSIsContainer }
share|improve this answer

In Powershell 3.0, it is simpler,

gci -Directory #List only directories
gci -File #List only files

This is even shorter,

gci -ad # alias for -Directory
gci -af # alias for -File
share|improve this answer

In PowerShell 3.0 you can also use the newly added -Attributes parameter
(together with logical operators)

Get-ChildItem -Recurse -Attributes !Directory+!System


dir -r -Attributes !D
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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