Dim WinDir As String
我觉得应该定义为Dim WinDir As String *256
然后把得到的路径和目录长度用MID$来得到,这个结果就是函数的结果

解决方案 »

  1.   

    fs.CopyFile "a", "d:\2"
    应该是fs.CopyFile a, "d:\2"吧, a好像是变量
      

  2.   


    WinDir = Space(MAX_PATH)
    改成如下:
    WinDir = String$(MAX_PATH, 0)
       
      

  3.   

    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Const MAX_PATH = 260
    '**-----<add>-----**
    Public strPath as String
    '**---------------**Private Function GetWinDir()
      Dim WinDir As String
      Dim ChrLen As String
      WinDir = Space(MAX_PATH)
      ChrLen = GetWindowsDirectory(WinDir, MAX_PATH)
      If ChrLen > MAX_PATH Then
        ChrLen = GetWindowsDirectory(WinDir, ChrLen)
      End If
      GetWinDir = Left(WinDir, ChrLen)
    End FunctionPrivate Sub Form_Load()
    Dim a As String
      Text1 = GetWinDir()
    '**------<delete>------**
      a = Text1 + "\" + "temp" + "\" + "*.*"
    '**--------------------**
    '**-----<add>-----**
      a = Text1 + "\" + "temp"
      strPath  = a
    '**---------------**
      Text2 = a
    End SubPrivate Sub Command1_Click()
    '**------<delete>------**
    'Set fs = CreateObject("Scripting.FileSystemObject")
    '   fs.CopyFile "a", "d:\2"
    '**--------------------**
    '**-----<add>-----**
    Dim fs As Object
    Set fs = CreateObject("Scripting.FileSystemObject")
       fs.CopyFolder strPath, "d:\2"
    '**---------------**
    End Sub
    通过测试一定好用
      

  4.   

    谢谢各位,该问题已由 yangzhiguo(小楊) 解决,再次表示感谢