谢谢版主的帮助。
我想了一下,我提出的问题有瑕疵,未能想周全。应该考虑到再下一层或几层子目录的问题。这就涉及了历遍所有子目录的问题。经过再查找资料,重写程序如下:
Public Sub HaalDirOp(ByVal Path$)
Dim vDirName As String, LastDir As String, i As Integer
i = -1
Screen.MousePointer = vbHourglass
If Right(Path$, 1) <> "\" Then Path$ = Path$ & "\"
vDirName = Dir(Path, vbDirectory) ' Retrieve the first entry.
Do While Not vDirName = ""
If vDirName <> "." And vDirName <> ".." Then
If (GetAttr(Path & vDirName) And vbDirectory) = vbDirectory Then
LastDir = vDirName
'MsgBox vDirName
List1.AddItem Path$ & vDirName
If Len(vDirName) > 6 Then
i = i + 1
Label1(i).Caption = vDirName
End If
Call HaalDirOp(Path$ & vDirName)
vDirName = Dir(Path$, vbDirectory)
Do Until vDirName = LastDir Or vDirName = ""
vDirName = Dir
Loop
If vDirName = "" Then Exit Do
End If
End If
vDirName = Dir
Loop
Screen.MousePointer = vbNormal
End Sub
Private Sub Command1_Click()
HaalDirOp "c:\aabbcc\1234\"
End Sub
这段程序解决了历遍N层子目录,挑选出满足条件的目录名在label中显示。完全达到我的要求。
在这里再次感谢版主的帮助!