從網路上找到的一段code, 但一直有問題,
就是第二次FtpFindFirstFile它的值就會出現0,
可是它明明就有 InternetCloseHandle hList ,
到現在還是不知為何不行 !!!http://www.dreamincode.net/code/snippet635.htm
Public Function FtpRemoveDirectory(ByVal hConnect As Long, ByVal dirName As String) As Boolean
    Dim hList As Long
    Dim WFDI As WIN32_FIND_DATA
    Dim fName As String
    Dim dirDepth As Byte
    Dim fileNum As Integer
   
    FtpSetCurrentDirectory hConnect, dirName
    DoEvents
    dirDepth = 1
   
loopPoint:
    While dirDepth
        hList = FtpFindFirstFile(hConnect, "*.*", WFDI, 0, 0)
        If hList Then
            Do
                fName = Left(WFDI.cFileName, instr(1,WFDI.cFileName, Chr(0),0)-1)
                If fName <> "." And fName <> ".." Then
                    If WFDI.dwFileAttributes = 16 Then
                        If FtpCommand(hConnect, False, 2, "rmd "  fName, 0, hTest) = False Then
                            FtpSetCurrentDirectory hConnect, fName
                            DoEvents
                            InternetCloseHandle hList
                            DoEvents
                            dirDepth = dirDepth + 1
                            GoTo loopPoint
                        End If
                    Else
                        FtpDeleteFile hConnect, fName
                    End If
                End If
            Loop While InternetFindNextFile(hList, WFDI)
        End If
        FtpSetCurrentDirectory hConnect, ".."
        DoEvents
        InternetCloseHandle hList
        DoEvents
        dirDepth = dirDepth - 1
    Wend
   
    InternetCloseHandle hList
    If FtpCommand(hConnect, False, 2, "rmd "  dirName, 0, hTest) = True Then
        FtpRemoveDirectory = True
    Else
        FtpRemoveDirectory = False
    End If
End Function

解决方案 »

  1.   

    介绍个控件ChilkatFTP。
    ChilkatFTP1.RemoveRemoteDir
      

  2.   

    ChilkatFTP 用在VBA  為何會無法connect ???
      

  3.   

    汗,vba里没用过。
    我的exe里是
        ChilkatFTP1.HostName = FTPHost
        ChilkatFTP1.Username = FTPUserName
        ChilkatFTP1.Password = FTPPassword
        
        Success = ChilkatFTP1.Connect
      

  4.   

    若VBA 無法用 ChilkatFTP,那原來的問題會是出在哪兒?
      

  5.   

    問題已經解決,原來的code 是沒問題的,
    也提供給大家參考,
    我是用在VBA,也行!!!