vb中的dir跟dos的dir有区别?
以下是文件夹中的文件:ABC.ETX
ABC.ETX_INF
ABC.ETX_EKO
DEF.ETX
DEF.ETX_INF
DEF.ETX_EKO
我只想找*.ETX的文件
用dir("*.etx")竟然将.etx_inf和.etx_eko的文件也搜索出来了 无代码无易做图,你怎么找的帖出来大家看看
按上面文件搜索 *.pat的文件
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
找出
abc.pat
abc.pat_inf
abc.pat_msk
之类的也找出来
其它我只要abc.pat
其它两个不要 试试这个,刚出炉的
'从菜单“工程”->“引用”->Microsoft Scripting RunTime谢谢,除FSO外,我上面的办法有没有办法优化 我该走了,回来再试试
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
取得扩展名,看是不是pat
Dim x
x = Dir("c:\*.txt")
While x <> ""
If Len(x) - InStrRev(x, ".") = 3 Then Debug.Print x
x = Dir
Wend
补充:VB , 基础类