KnowDotNet

Enumerate a Directory in .NET

by William Ryan

Well, this is a very simple example and nothing too special, but it's a common request on many newsgroups.

So, how do you walk through a directory in .NET?

Dim d As New DirectoryInfo("C:\")
Dim f As FileInfo
  
For Each f In d.GetFiles
      Debug.WriteLine(f.ToString)
  
Next


Now, this is a really simple but it's the basis of a lot of file manipulation.  You can easily implement this with recursionn so that you can offer 'include subdirectories' functionality.