Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 63
  • Last Modified:

Count files in a directory that start with specific letters

Hi:

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

Thanks
0
LuckyLucks
Asked:
LuckyLucks
  • 2
2 Solutions
 
QlemoC++ DeveloperCommented:
@(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
 
oBdACommented:
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
 
QlemoC++ DeveloperCommented:
Grin. I didn't expect the match going into thousands :D.
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now