窗口与控件事件
文件查找_AfterLoad
List11.clear '清除全局变量List11原来的值
文件查找_Button1_Click
e.Form.Controls("TextBox2").value
= Nothing
If
e.Form.Controls("TextBox1").value Is Nothing Then
Else
Dim s As String =
e.Form.Controls("TextBox1").value
'List11.clear '清除全局变量List11原来的值
If List11.count = 0 Then
Dim ds() As System.IO.DriveInfo =
System.IO.DriveInfo.GetDrives()'检索驱动器名称(盘符)
For i As Integer = 0 To ds.Length
- 1 '盘符
If FileSys.DirectoryExists(ds(i).Name) Then
'判断是否为有效盘符
'List11.Add(ds(i).Name) '添加目录
List11.AddRange(FileSys.GetFiles(ds(i).Name)) '添加文件
Functions.Execute("FMJ",
ds(i).Name) '非末级目录放入递归函数,结果输出到全局变量List11
End If
Next
End If
Dim ii As Integer
Dim ss As String
For Each nm As String In List11
If nm.contains(s) Then
ii = ii+1
If ss = Nothing Then
ss = nm
Else
ss = ss & vbcrlf & nm
End If
End If
Next
ss = "共找到 " & ii
& " 条记录" & vbcrlf & ss
e.Form.Controls("TextBox2").value
= ss
End If
文件查找_Button2_Click
e.Form.Controls("TextBox2").value
= Nothing
If
e.Form.Controls("TextBox1").value Is Nothing Then
Else
Dim s As String =
e.Form.Controls("TextBox1").value
List11.clear '清除全局变量List11原来的值
Dim ds() As System.IO.DriveInfo =
System.IO.DriveInfo.GetDrives()'检索驱动器名称(盘符)
For i As Integer = 0 To ds.Length
- 1 '盘符
If FileSys.DirectoryExists(ds(i).Name) Then
'判断是否为有效盘符
'List11.Add(ds(i).Name) '添加目录
List11.AddRange(FileSys.GetFiles(ds(i).Name)) '添加文件
Functions.Execute("FMJ",
ds(i).Name) '非末级目录放入递归函数,结果输出到全局变量List11
End If
Next
Dim ii As Integer
Dim ss As String
For Each nm As String In List11
If nm.contains(s) Then
ii = ii+1
If ss = Nothing Then
ss = nm
Else
ss = ss & vbcrlf & nm
End If
End If
Next
ss = "共找到 " & ii
& " 条记录" & vbcrlf & ss
e.Form.Controls("TextBox2").value
= ss
End If
自定义函数
FMJ
Dim str As String = args(0) '非末级目录
For Each dir As String In
FileSys.GetDirectories(str) '遍历目录
Dim ifo As new FileInfo(dir) '用于处理文件
If ifo.Hidden = False Then '
'List11.Add(dir) '添加目录
List11.AddRange(FileSys.GetFiles(dir))
'添加文件
If FileSys.GetDirectories(dir).count =
0 Then '如果为末级目录
Else
Functions.Execute("FMJ",dir) '再次循环
End If
End If
Next
全局代码
Public List11 As New List(Of
String)