# Re: 用vb6取得某个目录下的所有目录----可以使用dir()

Posted by 小v on October 15, 1999 at 08:47:40:

In Reply to: 用vb6取得某个目录下的所有目录(不用Dirlist) posted by aa on October 14, 1999 at 19:43:05:

: 用vb6取得某个目录下的所有目录(不用Dirlist)

使用DIR(), 以下范例摘自vb6使用说明档:

Dim MyPath As String, MyName As String
MyPath = "c:\win95\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

Follow Ups: