我基本上遵循 MS 的示例。以下是示例。
Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
Try
' Only get files that begin with the letter "c."
Dim dirs As String() = Directory.GetFiles("c:\", "c*")
Console.WriteLine("The number of files starting with c is {0}.", dirs.Length)
Dim dir As String
For Each dir In dirs
Console.WriteLine(dir)
Next
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
我稍微修改一下,这样我就可以将它用作文件搜索功能。但是,“For Each f In Directory.GetFiles(d, FileName)”处出现错误。我做错了什么?
Public Sub DirSearch(ByVal sDir As String, ByVal FileName As String)
Dim d As String
Dim f As String
Try
For Each d In Directory.GetDirectories(sDir)
For Each f In Directory.GetFiles(d, FileName)
If f = FileName Then
Form1.TextBox4.Text = "1"
Else
Form1.TextBox4.Text = "0"
End If
Next
DirSearch(d, FileName)
Next
Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
我发现这个,这解决了我的问题
Public Sub DirSearch(ByVal sDir As String, ByVal FileName As String)
For Each foundFile As String In My.Computer.FileSystem.GetFiles(sDir, FileIO.SearchOption.SearchAllSubDirectories, FileName)
"Do the work here"
Next
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)