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 dir
1 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.
-
And of course you can substitute
ls
fordir
if you prefer, or evenGet-ChildItem
if you’re feeling particularly masochistic. ↩︎