7,763
社区成员
发帖
与我相关
我的任务
分享
Dim x
x = Dir("c:\*.txt")
While x <> ""
If Len(x) - InStrRev(x, ".") = 3 Then Debug.Print x
x = Dir
Wend
'从菜单“工程”->“引用”->Microsoft Scripting RunTime
Dim Flder As String
Private Sub Command1_Click()
Flder = ""
Flder = GetFolder
If Flder = "" Then Exit Sub
Me.Caption = Flder
List1.Clear
Dim FSO As New FileSystemObject
Dim FL As File
For Each FL In FSO.GetFolder(Flder).Files
If ExtName(FL.Name) = "pat" Then
List1.AddItem FL.Name
End If
Next
End Sub
Private Function ExtName(ByVal PathName As String) As String
'得到文件的扩展名
aa = InStr(1, PathName, ".")
bb = PathName
Do While aa >= 0
bb = Mid(bb, InStr(1, bb, ".") + 1, Len(bb))
aa = aa - 1
Loop
ExtName = bb
End Function
Sub SearchFile(FolderName As String)
Dim tmpf As String
Dim FileName As String, tmp As String
FileName = Dir(FolderName & "\*.pat")
Do While Not FileName = ""
If FileName <> "." And FileName <> ".." Then
tmp = FolderName & "\" & FileName
tmpf = FileName
If GetAttr(tmp) <> vbDirectory Then
List1.AddItem Left(tmpf, InStrRev(tmpf, ".") - 1)
End If
End If
FileName = Dir
Loop
End Sub
Private Sub Command1_Click()
SearchFile "d:\code\pat"
End Sub