Click here to Skip to main content
Click here to Skip to main content

Enhanced version of VB.NET GetFiles

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

Introduction

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.

Background

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" _
    )
    Console.WriteLine(file.ToString)
Next

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.

History

  • Initial release: November 21, 2008.

License

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

Share

About the Author

LeeBear
Systems Engineer PRGX
United States United States
No Biography provided

Comments and Discussions

 
QuestionGreat job PinmemberN. Henrik Lauridsen3-Jul-13 1:50 
QuestionAhum? PinmemberZaegra14-May-09 9:09 
AnswerRe: Ahum? PinmemberLeeBear3-Jul-13 3:38 
GeneralMy vote of 1 PinmemberProJester124-Nov-08 11:09 
nonsence
GeneralMy vote of 1 PinmemberAxelM23-Nov-08 20:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.8.140821.2 | Last Updated 21 Nov 2008
Article Copyright 2008 by LeeBear
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid