VB求助:扫描文件将List1里文件名为收索对象路径显示在List2里
'以下是收索代码'问题是为:不知道怎么将List1的全部(全部哦!可以声明:i 依次扫描..)收索文件名为收索对象
'收索到了就会将文件的路径显示在List2的里面!
'我是新手拜托各位老大帮帮忙!
工程事例图片:
Private Function SearchPath(ByVal sPath As String, ByVal FindName As String) As Boolean
Dim sChildDir() As String
Dim sFileName As String
Dim lDirNum As Long
Dim lCount As Long
On Error GoTo SearchPathErr
If Right(sPath, 1) <> "\" Then sPath = sPath + "\"
sFileName = Dir(sPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
While sFileName <> ""
Me.Caption = sPath '这里在标题栏显示当前查找的目录、你可以根据需要去掉
'因为文件过多可能会给人死掉的假象、所以标题栏显示出当前查找的目录
DoEvents
If (GetAttr(sPath + sFileName) And vbDirectory) = vbDirectory Then
If sFileName <> "." And sFileName <> ".." Then
ReDim Preserve sChildDir(lDirNum) As String
sChildDir(lDirNum) = sFileName
lDirNum = lDirNum + 1
End If
Else
If UCase$(FindName) = UCase$(sFileName) Then
Text1 = sPath & sFileName
'If MsgBox("已经找到文件、存在于目录:" & sPath & vbCrLf & "是否停止查找并运行?", vbQuestion + vbYesNo) = vbYes Then
'Call Shell("cmd /c start " & sPath & sFileName, vbHide)
'Exit Function
' End If
End If
End If
sFileName = Dir
Wend
For lCount = 0 To lDirNum - 1
Call SearchPath(sPath + sChildDir(lCount), FindName)
Next
Erase sChildDir
SearchPath = True
Exit Function
SearchPathErr:
SearchPath = False
End Function
Private Sub Command1_Click()
SearchPath "c:\", "小明.txt"'不知道怎么设置不知道怎么将List1的全部(全部哦!可以声明:i 依次扫描..)收索文件名为收索对象
End Sub
如果老大们觉得以上的代码不符合要求请大家帮我想想这个问题吧!要的目的是:将List1的全部(全部哦!可以声明:i 依次扫描..)收索文件名为收索对象
'收索到了就会将文件的路径显示在List2的里面!