# Re: 还是有问题.

Posted by 晓芳 on December 24, 1998 at 21:36:46:

In Reply to: Re: 还是有问题. posted by 晓芳 on December 24, 1998 at 21:00:44:

:
: : : 下面这段程式可以将C:\的所有子目录全找出来,再配合
: : : 上面的DIR()就可以达到你的要求了!
: : : Private Sub Command1_Click()
: : : Dim MYPATH As String, MYNAME As String
: : : MYPATH = "c:\" ' 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
: : : End Sub
: : 但是这段程式码只能找出在根目录下一层的目录,再下一层的目录又怎样找出来呢?
: 既然知道根目录下的目录名称,假设有一目录叫做jeff,
: 若要找出下一层的目录,就将上面程式的
: MYPATH="C:\"改成MYPATH="C:\JEFF\"
: 这样就可以了!

其实还有一个更简单的方法:
那就是使用DirListBox和FileListBox
Private Sub Command1_Click()
Dim I As Integer
File1.Path = "C:\DOS"
Fiel1.Pattern="*.EXE"
For I = 0 To File1.ListCount - 1
Debug.Print File1.List(I)
Next
End Sub

Private Sub Command2_Click()
Dim I As Integer
Dir1.Path = "C:\"
For I = 0 To Dir1.ListCount - 1
Debug.Print Dir1.List(I)
Next
End Sub
自己动动脑吧!

Follow Ups: