Tell me more ×
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

2 Answers

up vote 15 down vote accepted

Try this:

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

In Powershell 3.0, it is simpler,

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

This is even shorter,

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

Your Answer

 
discard

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.