使用VB菜单:[工程] -- [引用] -- ,勾选:Microsoft Scriptiong Runtime,[确定]
在窗体上添加1个文本框,设置MultiLine 属性为True,ScrollBars 属性为3-Both
添加1个按钮:
代码如下,复制即可用:
Option Explicit
Private nnnn As Integer
Private MyFile As String
Private Sub Command1_Click()
nnnn = 0
MyFile = ""
OutFile "D:\", "123.exe"
Text1.Text = MyFile
MsgBox "一共找到:" & nnnn & " 个文件"
End Sub
'递归过程--返回指定文件夹下的指定文件
Private Sub OutFile(ByVal MyFolder As String, ByVal MyFileName As String)
Dim fs, f, f1, s, sf, f2, mf
Dim L As Integer '寻找的文件名长度
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(MyFolder)
Set sf = f.SubFolders
For Each f1 In sf
OutFile f1, MyFileName
Next
L = Len(MyFileName)
Set mf = f.Files
For Each f2 In mf
If Right(f2, L) = MyFileName Then
nnnn = nnnn + 1
MyFile = MyFile & f2 & vbCrLf
End If
Next
End Sub
追问如何把查找到的文件路径添加到text1.text里面啊
追答按照上面说的做,没有问题.
结果放到文本框语句:
Text1.Text = MyFile