Dim drvbitmask&, maxpwr%, pwr%
On Error Resume Next
FileSpec$ = InputBox("Enter a file spec:" & vbCrLf & vbCrLf & _
"Searching will begin at drive A and continue " & _
"until no more drives are found. " & _
"Click Stop! at any time." & vbCrLf & _
"The * and ? wildcards can be used.", _
"Find File(s)", "*.exe")
drvbitmask& = GetLogicalDrives()
If drvbitmask& Then
maxpwr% = Int(Log(drvbitmask&) / Log(2)) ' a little math...
For pwr% = 0 To maxpwr%
If Running% And (2 ^ pwr% And drvbitmask&) Then _
Call SearchDirs(Chr$(vbKeyA + pwr%) & ":\")
Next
End If
新建工程
添加一个filelistbox 一个dirlistbox 一个drivelistbox 两个listbox 一个commandbutton
代码:
Private Sub Command1_Click()
List2.Clear
File1.Pattern = "*.bmp"
Dir1.Path = "c:\"
For i = 0 To Dir1.ListCount - 1
List2.AddItem Dir1.List(i)
Next
File1.Path = Dir1.Path
For j = 0 To File1.ListCount - 1
List1.AddItem Dir1.Path + File1.List(j)
Next
j = 0
On Local Error GoTo en
List2.ListIndex = j
While s < List2.ListCount
Dir1.Path = List2.List(s) + "\"
File1.Path = Dir1.Path
For j = 0 To File1.ListCount - 1
List1.AddItem Dir1.Path + "\" + File1.List(j)
Next
For t = 0 To Dir1.ListCount - 1
List2.AddItem Dir1.List(t)
Next
s = s + 1
Wend
en:
End Sub