vb怎样在文件夹中搜索指定名称的文件,并用msgbox将文件位置输出?我新手请将代码解释下。
Public Sub ShowFolderList(folderspec)
On Error Resume Next
Dim fs, f, f1, s, sf
Dim hs, h, h1, hf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 In sf
If Dir(folderspec & "\" & f1.Name & "\" & Text2, vbDirectory) <> "" Then
MsgBox folderspec & "\" & f1.Name & "\" & Text2
Exit For
End If
If folderspec & "\" & Text2 <> "" Then Call ShowFolderList(folderspec & "\" & f1.Name)
Next
End Sub
Private Sub Command1_Click()
If Right(Text1, 1) = "\" Then Text1 = Left(Text1, Len(Text1) - 1)
ShowFolderList (Text1)
End Sub
附件里是源码