我的代码如下:Private Sub Command1_Click()
Dim str1 As String, path As Stringpath = "c:\tc\"str1 = aaa(path)Text1.Text = str1
End Sub
Function aaa(path)Dim str As String, MyName As Stringstr = ""MyName = Dir(path, vbDirectory) 'will list files and folders
Do While MyName <> ""
    If MyName <> "." And MyName <> ".." And ((GetAttr(path & MyName) And vbDirectory) = vbDirectory) Then
        str = str & aaa(path & MyName & "\")
    Else
        str = str & MyName & vbCrLf
    End If
    MyName = Dir  '到时候这一行就会出问题:invalid procedure or argument
Loopaaa = strEnd Function

解决方案 »

  1.   

    如果屏蔽掉str = str & aaa(path & MyName & "\")行就不会出问题,大家可以运行看看
      

  2.   

    http://community.csdn.net/Expert/topic/3183/3183074.xml?temp=.7244379
      

  3.   

    To: hhjjhjhj(大头)你的代码我看过了,你是用FileSystemObject方式你能不能按我的方式帮我改写一下
      

  4.   

    不可以这样递归。因为对同一路径反复使用 DIR 时,不用参数:
      MyName = Dir
    以使过程次第进行。但是当你从下级目录返回时,路径已经改变。
      

  5.   

    注意,摘自 MSDN:Dir 会返回匹配 pathname 的第一个文件名。若想得到其它匹配 pathname 的文件名,再一次调用 Dir,且不要使用参数。如果已没有合乎条件的文件,则 Dir 会返回一个零长度字符串 ("")。一旦返回值为零长度字符串,并要再次调用 Dir 时,就必须指定 pathname,否则会产生错误。不必访问到所有匹配当前 pathname 的文件名,就可以改变到一个新的 pathname 上。*****但是,不能以递归方式来调用 Dir 函数。以 vbDirectory 属性来调用 Dir 不能连续地返回子目录。*****