• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 65
  • 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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
@(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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Grin. I didn't expect the match going into thousands :D.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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