tyler butler

Count Files In A Directory

Need to count files in a directory? Try this one line of PowerShell:

(dir | where {$_.GetType() -match "fileInfo"} | measure-object).count

You can also add a -r parameter (-r means recursive) to the first dir1 command and get a complete count of all files in all subdirectories under the current path.

This comes in handy, though I do wish it was a little more succinct.


  1. And of course you can substitute ls for dir if you prefer, or even Get-ChildItem if you’re feeling particularly masochistic. ↩︎