Solved

Count files in a directory that start with specific letters

Posted on 2016-07-18
3
48 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 69

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 69

Expert Comment

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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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