日期:2009-11-02  浏览次数:20413 次

遍历所有文件夹的递归函数(epower2002)

Sub Main()
    ProcessDirectory("E:\My Documents")

    Console.ReadLine()
  End Sub

  Private Sub ProcessDirectory(ByVal targetDirectory As String)
    If Directory.Exists(targetDirectory) Then
      If Directory.GetFileSystemEntries(targetDirectory).Length = 0 Then
        ' Empty folder
        Console.WriteLine("Folder " & targetDirectory & " is empty")
      Else
        ' Recurse subdirectories of this directory
        Dim subdirectory As String
        Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)
        For Each subdirectory In subdirectoryEntries
          Console.WriteLine("Folder is " & subdirectory)
          ProcessDirectory(subdirectory)
        Next subdirectory
      End If
    End If
  End Sub