要求: 希望得到c:\目录下所有子目录的名称 如只有windows,program file
以下代码能得到了如c:\windows c:\program file这样带路径的名字 我不想要文件路径
     Dim fld As Folder
     Set fld = fso.GetFolder("c:\")
     For Each i In fld.SubFolders.Name
        Lst.AddItem (i)
     Next i
请大家指点
另:祝大家51节快乐

解决方案 »

  1.   

    可以这样去写:
         Dim fld As Folder
         Set fld = fso.GetFolder("c:\")
         For Each i In fld.SubFolders.Name
            Lst.AddItem (i)
         '增加代码     '从右开始检测字符串,检测到第一个“\”时,停止检测删除“\”之前的部分
         '剩下的部分当然就是你想要的啦     '继续循环
         Next i
      

  2.   

    Dim strName As String
      strName = Dir("c:\", vbDirectory)
      While strName <> ""
        If (GetAttr("c:\" & strName) And vbDirectory) Then MsgBox strName
        strName = Dir()
      Wend
    '--------------------- Code End -----------------
    '你试一试这个代码吧。
    '参考:http://expert.csdn.net/Expert/topic/2769/2769041.xml
    'If (GetAttr("c:\" & strName) And vbDirectory) Then 这一句用来判断
    '  所得文件名是否为目录