VB过程:在已知磁盘中查找扩展名是jpg的文件,找到第一个符合条件文件后返回文件所在的完整路径?

来源:百度知道 编辑:UC知道 时间:2024/05/27 10:39:14
我用的VB6中文企业版,请给出完整的代码,谢谢!
谢谢zorrowh的回答,也许我的问题未说清。事先不知道文件的路径,只知道文件扩展名jpg和所在磁盘,写个函数通过扩展名返回*.jpg所在的完整路径。

窗体上有一个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
S