0

For example, I have following files in a folder

aaa001.txt

aaa002.txt

aaa003.txt

bbb001.txt

bbb002.txt

...

Is there any way I can count the number of files starting with "aaa" in this folder?

I can do Dir("*\aaa*.txt") in a loop while counting. But I'm wondering if there is a more efficient way of doing it.

Thanks.

got2nosth
  • 578
  • 2
  • 8
  • 27
  • 1
    Even though it is counting as you are, this answer details out some good code http://stackoverflow.com/a/22630255/1504882 – Elias Jul 18 '14 at 12:12
  • 1
    Dir I believe is the way to go. Another resource here as well http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba. If its running too slowly, maybe post what code you have so far, the issue might be the way it is setup rather than the function being expensive – ashareef Jul 18 '14 at 12:14
  • `dir aaa*.*|findstr /i /c:"File(s)"` – D.Ddgg Jul 18 '14 at 12:36

1 Answers1

0

I'm wondering if there is a more efficient way of doing it.

No. Dir is simple and as fast as can be.

Gustav
  • 53,498
  • 7
  • 29
  • 55