DEV Community

Ryan Palo
Ryan Palo

Posted on

2 2

Count Child Directories with PowerShell

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

I love the CLI so much!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay