我想按順序讀取文件夾中的一些文本文件路徑。但是,我只獲得第一個文件。從VB.NET的文件夾中一次獲取一個文件
我需要獲取第一個文件,執行一個計時器,獲取下一個文件路徑,執行一個計時器直到文件夾中的最後一個文件,然後停止。我怎樣才能解決這個問題?
Private zMailbox As String = "c:\Fold\"
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick
Dim finfo As New IO.DirectoryInfo(zMailbox)
For Each fi In finfo.GetFiles("*.txt")
TextBox1.Text = fi.FullName
Next
End Sub
多虧了貢獻低於我的代碼與文本框的值工作。但是,它會提供索引計數而不是我想要檢索的路徑。
Private zMailbox As String = "c:\Fold\"
Dim files As FileInfo()
Dim index As Integer = 0
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles Button1.Click
Dim finfo As New IO.DirectoryInfo(zMailbox)
files = finfo.GetFiles("*.txt")
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick
If index >= files.Length Then
index = 0
End If
TextBox1.Text = (ListBox1.Items.Add(files(index)))
index += 1
End Sub
這是不會做你的想法。它會在每個勾號上執行GetFiles。 – Plutonix