KnowDotNet NetRefactor

Enumerate a Directory in .NET

by William Ryan
Print this Article Discuss in Forums

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.  

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing