Dir("c:\", vbDirectory)可以返回c:\下的子目录,怎么用dir函数返回"c:\temp"目录下的子目录?

解决方案 »

  1.   

    dim tmp as string
    tmp = Dir("c:\", vbDirectory)
    Do While tmp <> ""   ' 开始循环。
       If tmp <> "." And tmp <> ".." Then
          ' 使用位比较来确定 tmp 代表一目录。
             Debug.Print tmp ' 如果它是一个目录,将其名称显示出来。
       End If
       tmp = Dir   ' 查找下一个目录。
    Loop
      

  2.   

    显示文件夹:
    dim tmp as string
    tmp = Dir("c:\", vbDirectory)
    Do While tmp <> ""   ' 开始循环。
       If tmp <> "." And tmp <> ".." Then
          ' 使用位比较来确定 tmp 代表一目录。
          If (GetAttr("c:\"& tmp) And vbDirectory) = vbDirectory Then
             Debug.Print tmp ' 如果它是一个目录,将其名称显示出来。
          End If
       End If
       tmp = Dir   ' 查找下一个目录。
    Loop
      

  3.   

    错了,错了
    我说的是在c:\temp目录下的子文件夹,不是c:\下的子文件夹!!!
      

  4.   

    我在c:\temp下面有个tt1的文件夹,怎么把这个tt1的名字返回啊?不是要返回temp的文件夹名字
      

  5.   

    Dim str As String
    str = Dir("c:\temp\*", vbDirectory)
    Do Until str = ""
      If GetAttr("c:\temp\" & str) = vbDirectory Then Print str
      str = Dir(, vbDirectory)
    Loop