VB过程:在已知磁盘中查找扩展名是jpg的文件,找到第一个符合条件文件后返回文件所在的完整路径?
1个回答
2013-10-12
展开全部
窗体上有一个LABEL 一个TEXT text的MultiLine 设为TRUE 一个COMMAND
Public Sub SeachFile(ByVal strPath As String)
On Error Resume Next
Dim Fso As Object
Dim Fol As Object
Dim Fil As Object
Dim MyName As String
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fol = Fso.GetFolder(strPath)
If strPath <> "" Then
If Right(strPath, 1) = "\\" Then
strPath = Left(strPath, Len(strPath) - 1)
End If
Label1.Caption = strPath
DoEvents
MyName = Dir(strPath & "\\ldifde.exe")'这里改你想查找的文件名
Do While MyName <> "" ' 开始循环。
If Len(MyName) > 0 Then
Text1.Text = Text1.Text & vbCrLf & strPath & "\\" & MyName
Exit Do
End If
MyName = Dir()
Loop
End If
'扫描子目录
For Each Fol In Fol.SubFolders
SeachFile Fol
Next
End Sub
Private Sub Command1_Click()
Text1.Text = ""
Call SeachFile("c:\\")
End Sub
我试过了,可以搜
Public Sub SeachFile(ByVal strPath As String)
On Error Resume Next
Dim Fso As Object
Dim Fol As Object
Dim Fil As Object
Dim MyName As String
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fol = Fso.GetFolder(strPath)
If strPath <> "" Then
If Right(strPath, 1) = "\\" Then
strPath = Left(strPath, Len(strPath) - 1)
End If
Label1.Caption = strPath
DoEvents
MyName = Dir(strPath & "\\ldifde.exe")'这里改你想查找的文件名
Do While MyName <> "" ' 开始循环。
If Len(MyName) > 0 Then
Text1.Text = Text1.Text & vbCrLf & strPath & "\\" & MyName
Exit Do
End If
MyName = Dir()
Loop
End If
'扫描子目录
For Each Fol In Fol.SubFolders
SeachFile Fol
Next
End Sub
Private Sub Command1_Click()
Text1.Text = ""
Call SeachFile("c:\\")
End Sub
我试过了,可以搜
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询