驅動器和文件夾列表是用來選擇妳想要搜索的文件夾。
程序運行時選中妳想要搜索的文件夾,單擊搜索按鈕。該文件夾下面所有的文件及子文件夾裏面的文件都列到列表框中。
將代碼復制到窗體即可。代碼如下:
Private Sub Command1_Click()
List1.Clear
sosuofile (Dir1.List(Dir1.ListIndex))
MsgBox "搜索完畢!,***找到" + Str(List1.ListCount) + "條記錄。", vbOKOnly + vbExclamation, "提示"
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Sub sosuofile(MyPath As String)
Dim Myname As String
Dim dir_i() As String
Dim i, idir As Long
If Right(MyPath, 1) <> "\\" Then MyPath = MyPath + "\\"
Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
Do While Myname <> ""
If Myname <> "." And Myname <> ".." Then
If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目錄
idir = idir + 1
ReDim Preserve dir_i(idir) As String
dir_i(idir - 1) = Myname
Else: List1.AddItem "" & MyPath & " " & Myname '把找到的文件顯示到列表框中
End If
End If
Myname = Dir '搜索下壹項
Loop
For i = 0 To idir - 1
Call sosuofile(MyPath + dir_i(i))
Next i
ReDim dir_i(0) As String
End Sub
Private Sub Form_Load()
Command1.Caption = "搜索"
End Sub