Part of my job requires batch processing large amounts of files, on the order of 100,000 to 1,000,000. Back in VB6 days, the code found each file in the directory. When upgrading to .NET, the
GetFiles method was implemented and performance tanked. This is an implementation of the
FindNextFile that can be called just like
GetFiles with a bonus of returning all of the file attributes too.
There are other versions of this out there, mostly in C# format, using the
yield return which is available in VB.NET at this time.
This implementation handles multiple wildcard matches, but only one source directory.
It would be easy to add an
Enumerator class around the
Files class to handle multiple directories, but I did not have need for that at this time.
Using the Code
This is just a class module and a help file to explain the class. You simply add the class to your project and implement it just like the Microsoft version of
For Each file As Files.WIN32_FIND_DATA In _
This example will find all the text and document files on the C: drive.
Points of Interest
Unlike the .NET version of
GetFiles, this version will look into any sub-directory and will not generate errors doing so.
- Initial release: November 21, 2008.