Solved

Count files in a directory that start with specific letters

Posted on 2016-07-18
3
35 Views
Last Modified: 2016-08-15
Hi:

 I need to search for files in a specific directory that start with a letter A. or AB. in Windows Powershell.

Thanks
0
Comment
Question by:LuckyLucks
  • 2
3 Comments
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 41717542
@(Get-ChildItem C:\Temp\EE\Path -Filter 'A*').Count

Open in new window

This will not search in subfolders - if you need that, add -recurse to the command in brackets.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points
ID: 41717572
Hey, are you same Qlemo who wants to save resources? ;)
That certainly works, but just for counting, it's a waste of memory, because PS needs to build a potentially huge array. Try that with -recurse on C:\Windows - the PS instance here goes from 20MB to 340MB (yes, a [GC]::collect() will reduce that, but still ...)
This is less resource intensive if it's just about counting:
(Get-ChildItem C:\Windows -Filter "A*" | Measure-Object).Count

Open in new window

Or the good old fashioned way:
$Count = 0; Get-ChildItem C:\Windows -Filter "A*" | % {$Count++}; $Count

Open in new window

0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41717708
Grin. I didn't expect the match going into thousands :D.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now