Click here to Skip to main content
11,931,104 members (63,269 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked

Enhanced version of VB.NET GetFiles

, 21 Nov 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
This is an inline enumeration of files instead of building an array first.


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 FindFirstFile, 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 GetFiles.

For Each file As Files.WIN32_FIND_DATA In _
    Files.GetFilesEx _
    ( _
        "c:\", _
        SYSTEM.FileIO.SearchOption.SearchAllSubDirectories, _
        "*.txt,*.doc" _

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Systems Engineer PRGX
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionGreat job Pin
N. Henrik Lauridsen3-Jul-13 2:50
memberN. Henrik Lauridsen3-Jul-13 2:50 
QuestionAhum? Pin
Zaegra14-May-09 10:09
memberZaegra14-May-09 10:09 
AnswerRe: Ahum? Pin
LeeBear3-Jul-13 4:38
memberLeeBear3-Jul-13 4:38 
GeneralMy vote of 1 Pin
ProJester124-Nov-08 12:09
memberProJester124-Nov-08 12:09 
GeneralMy vote of 1 Pin
AxelM23-Nov-08 21:51
memberAxelM23-Nov-08 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 21 Nov 2008
Article Copyright 2008 by LeeBear
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid