It has been a while since I looked at VB.NET, but in C# you could do something like this:
static void Main(string[] args)
{
string filePath = @"I:\Archive\2009.12.21c";
List<string> extensions = new List<string>{
".jpg",
".jpeg",
".png",
};
string[] countImages = System.IO.Directory.GetFiles(filePath);
foreach (string file in countImages)
{
if (extensions.Contains(System.IO.Path.GetExtension(file).ToLowerInvariant()))
{
//This is where you can add to your count for found files
}
}
}
These are all .NET classes, and should be easy enough to translate back to VB.NET.
Edit for @Trade
@Trade OK, was able to get to it. Ran your code (converted to C#) and my code, 6 loops mine then yours, then 6 more yours then mine. The 6 times yours followed by 6 runs through mine, then flipped them (All to make sure not a JIT warm up) and the results: The difference is more than an order of magnitude in preference of the approach I used:
Example: Yours is enum2, mine was enum1
Found 37 with dir enum1 in 609
Found 37 with dir enum1 in 469
Found 37 with dir enum1 in 462
Found 37 with dir enum1 in 455
Found 37 with dir enum1 in 448
Found 37 with dir enum1 in 406
Found 37 with dir enum2 in 6314
Found 37 with dir enum2 in 6888
Found 37 with dir enum2 in 5439
Found 37 with dir enum2 in 5614
Found 37 with dir enum2 in 5824
Found 37 with dir enum2 in 6342
Here is the converted code for your method:
private static void enum2(string filePath, List<string> extensions)
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
int countCount = 0;
for (int i = 0; i < extensions.Count(); i++)
{
string curExt = extensions[i];
countCount += System.IO.Directory.GetFiles(filePath, "*" +
curExt, System.IO.SearchOption.TopDirectoryOnly).Length;
}
sw.Stop();
Console.WriteLine("Found {0} with dir enum2 in {1}",
countCount, sw.ElapsedTicks.ToString());
}