Solved

Count files in a directory that start with specific letters

Posted on 2016-07-18
3
51 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

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 84

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 70

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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