Directory.GetDirectories
はすべてのファイルを列挙し、クエリ可能なリストを返します。すべてのファイルがプリントアウトされ、その後、試してみて、デモンストレーション、あなたがあなたのコードを呼び出すと、デバッグを書き出す場合、ファイルが見つかり、getDirectories戻っているときに一時停止を取得するために
:
For Each filename As String In Directory.GetDirectories("C:\", "*.*", SearchOption.AllDirectories)
debug.writeline(filename)
Next
あなたはもちろん、ディレクトリを再帰的に列挙し、それが現在検索しているディレクトリを報告する何かをコードすることができます。これは効率的ではありませんが、操作の進行中にユーザーにフィードバックを提供します:
Private WithEvents _de As New DirectoryEnumerator()
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
Dim startPath As String = "C:\Windows\Temp"
_de.StartEnum(startPath)
'now we have the list of files
Debug.WriteLine("Files")
For Each filename In _de.FilesFound
Debug.WriteLine(filename)
Next
End Sub
Private Sub _de_CurrentDirectoryChanged(newDirectory As String) Handles _de.CurrentDirectoryChanged
Debug.WriteLine("Current Directory being searched:" & newDirectory)
End Sub
Private Class DirectoryEnumerator
Private _filesFound As List(Of String)
Public Event CurrentDirectoryChanged(newDirectory As String)
Public ReadOnly Property FilesFound As IReadOnlyList(Of String)
Get
Return _filesFound
End Get
End Property
Public Sub StartEnum(startPath As String)
_filesFound = New List(Of String)
EnumerateDirectory(startPath)
End Sub
Private Sub EnumerateDirectory(thisPath As String)
RaiseEvent CurrentDirectoryChanged(thisPath)
'add any files found in this directory to the list of files
_filesFound.AddRange(Directory.GetFiles(thisPath, "*.*"))
'enumerate any directories found
For Each thisDir In Directory.GetDirectories(thisPath)
EnumerateDirectory(thisDir)
Next
End Sub
End Class
素晴らしい、ありがとう! –