使用VB的FOS模型的FileSystemObject对象:
该对象需要引用,方法如下:
使用VB的菜单:[工程] -- [引用],在出现的窗口,勾选:Microsoft Scripting Runtiom
代码如下:
Private Sub Command1_Click()
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\")
Set sf = f.SubFolders
For Each f1 In sf
s = s & f1.Name
s = s & vbCrLf
Next
MsgBox s
End Sub