loading...

Count Child Directories with PowerShell

rpalo profile image Ryan Palo ・1 min read

At work, I received a supplier survey from a customer asking how many customers we have. My first thought was, "Ugh! I'm going to have to go into our system and figure out where those reports live and make sure I'm getting the right numbers from the right places." But then I remembered our server. And I remembered that I'm a programmer and we don't have to stand for things like manually counting.

Bada bing, bada boom:

gci -dir | measure

# Which is PowerShell auto-aliasing goodness for:
Get-ChildItem -Directory | Measure-Object

For good measure, we can get the job done in Bash the same way:

ls -d */ | wc -l

# I've used ls -d here rather than find because I wanted to skip hidden dirs

I love the CLI so much!

Posted on by:

rpalo profile

Ryan Palo

@rpalo

Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Message me on DEV!

Discussion

markdown guide