由于 Macintosh 不支持通配符,使用文件类型指定文件组。可以使用 MacID 函数指定文件类型而不用文件名。比如,下列语句返回当前文件夹中第一个TEXT文件的名称:
Dir("SomePath", MacID("TEXT"))
为选中文件夹中所有文件,指定一空串:
Dir("")
在 Microsoft Windows 中,如果在Dir函数中使用MacID函数,将产生错误。
任何大于256的attribute值都被认为是MacID 函数的值。
在第一次调用 Dir 函数时,必须指定 pathname,否则会产生错误。如果也指定了文件属性,那么就必须包括 pathname。
Dir 会返回匹配 pathname 的第一个文件名。若想得到其它匹配 pathname 的文件名,再一次调用 Dir,且不要使用参数。如果已没有合乎条件的文件,则 Dir 会返回一个零长度字符串 ("")。一旦返回值为零长度字符串,并要再次调用 Dir 时,就必须指定 pathname,否则会产生错误。不必访问到所有匹配当前 pathname 的文件名,就可以改变到一个新的 pathname 上。但是,不能以递归方式来调用 Dir 函数。以 vbDirectory 属性来调用 Dir 不能连续地返回子目录。
private Function SearchDirs(ByVal sPath As String, sFindDirs() As String, Optional ByVal bReset As Boolean = False) As Long
Dim sDir As String
Dim sSubDirs() As String
Dim Index As Long
Static Count As Long
If bReset Then
Count = 0
bReset = False
End If
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
Index = 0
sDir = Dir(sPath & "*.*", vbDirectory)
Do While Len(sDir)
If Left(sDir, 1) <> "." Then 'skip.and..
If GetAttr(sPath & sDir) And vbDirectory Then
Index = Index + 1
Count = Count + 1
'保存子目录名
ReDim Preserve sSubDirs(1 To Index)
sSubDirs(Index) = sPath & sDir & "\"
ReDim Preserve sFindDirs(1 To Count)
sFindDirs(Count) = sPath & sDir & "\"
End If
End If
sDir = Dir
Loop
For Index = 1 To Index
Call SearchDirs(sSubDirs(Index), sFindDirs())
Next Index
SearchDirs = Count
End Function
Private Sub Command2_Click()
Dim m_Dirs() As String
Dim m_DirCount As Long, i As Long
m_DirCount = SearchDirs("c:\dos", m_Dirs, True)
Combo1.Clear
If m_DirCount > 0 Then
For i = 1 To m_DirCount
Combo1.AddItem m_Dirs(i)
Next i
Combo1.ListIndex = 0
End If
End Sub
'多给一点分吧!!哈哈。。
================================================================
我是一个兵,来自老百姓。