Need to count files in a directory? Try this one line of PowerShell:
(dir | where {$_.GetType() -match "fileInfo"} | measure-object).countYou 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.
Footnotes
-
And of course you can substitute
lsfordirif you prefer, or evenGet-ChildItemif you’re feeling particularly masochistic.