Click here to Skip to main content
6,291,124 members and growing! (15,811 online)
Email Password   helpLost your password?
Languages » VB.NET » Utilities     Intermediate License: The Code Project Open License (CPOL)

Enhanced version of vb.net GetFiles

By LeeBear

This is an inline enumeration of files instead of building an array first
C#, VB (VB 7.x, VB 8.0, VB 9.0, VB 6), Windows (Win2K, WinXP, Win2003, Vista, TabletPC), .NET (.NET 2.0, .NET 3.0, .NET 3.5), Visual Studio (VS2005, VS2008), Dev
Posted:21 Nov 2008
Views:3,301
Bookmarked:7 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
5 votes for this article.
Popularity: 1.20 Rating: 1.71 out of 5
3 votes, 60.0%
1
1 vote, 20.0%
2
1 vote, 20.0%
3

4

5

Introduction

Part of my job requires batch processing large amounts of files, on the order of 100,000 to 1,000,000. Back in the 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 not a part of 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 an 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

Intial Release November 21, 2008

License

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

About the Author

LeeBear


Member

Occupation: Web Developer
Location: United States United States

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralAhum? PinmemberZaegra10:09 14 May '09  
GeneralMy vote of 1 PinmemberProJester112:09 24 Nov '08  
GeneralMy vote of 1 PinmemberAxelM21:51 23 Nov '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Nov 2008
Editor:
Copyright 2008 by LeeBear
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project