找回密码
 加入
搜索
查看: 2179|回复: 4

[AU3基础] 用_FTP_DirDelete 无法删除含有子目录的ftp服务器上的文件夹

[复制链接]
发表于 2011-11-21 20:32:37 | 显示全部楼层 |阅读模式
_FTP_DirDelete,,可以删除ftp 服务器上的空文件夹,但是无法删除,含有子文件夹和文件的目录,请问,有好用的udf么?
谢谢了
发表于 2011-11-21 20:36:12 | 显示全部楼层
应该是可以的吧!请把源码放上!
发表于 2011-11-21 21:16:41 | 显示全部楼层
是不是FTP服务器设置的问题呢?不然这个函数应该不是出现这种现象吧!
 楼主| 发表于 2011-11-22 08:50:05 | 显示全部楼层
回复 2# geshenggang4
#include <FTPEx.au3>
#include "CoProc.au3"

While 1
        $iPidotherfuc = _CoProc("ftp")
        Sleep(10000)
WEnd        

Func ftp()        
        Dim $downftpfileflag
        Dim $fFailIfExists
        $server = '172.21.16.46'
        $username = 'wwxsawis'
        $pass = 'awis123'
        
        $Open = _FTP_Open('SlipFinder ftp ')
        $Conn = _FTP_Connect($Open, $server, $username, $pass)
        $aFile = _FTP_ListToArray($Conn, 2)                ;只找文件
        If IsArray($aFile) Then 
                Sleep(2000)                        ;等待下,以防止机台产生数据中
                For $i= 1 To $aFile[0]                                
                        $filegroup=StringSplit($aFile[$i],".")
                        ;MsgBox(0,"",$filegroup[2])
                        If $filegroup[2] = "txt" Then                        ;如果是txt档,则下载此文件
                                $downftpfileflag=_FTP_FileGet($Conn,"/" & $aFile[$i] ,"C:" & $aFile[$i], $fFailIfExists = False)        ;false为不覆盖
                                MsgBox(0,"上传标志",$downftpfileflag ,1)
                                If $downftpfileflag = 1 Then                 ;判断是否下载成功,成功即可删除
                                        _FTP_FileDelete($Conn, "/" & $aFile[$i])
                                        MsgBox(0,"文件夹名",$filegroup[1])
                                        _FTP_DirDelete($Conn, "/" & $filegroup[1])
                                        MsgBox(0,"","上传后删除啦",1)
                                Else                                ;如果下载不成功,
                                        ;MsgBox(0,"@error",@error,1)
                                        $downftpfileflag=_FTP_FileGet($Conn,"/" & $aFile[$i] ,"C:" & $aFile[$i], $fFailIfExists = False)        
                                EndIf
                        Else                                         ;如果不是txt档,则直接删除 
                                _FTP_FileDelete($Conn, "/" & $aFile[$i])
                                MsgBox(0,"","直接删除啦",1)
                        EndIf                                
                Next                        
        EndIf        
        $Ftpc = _FTP_Close($Open)        
EndFunc
 楼主| 发表于 2011-11-22 08:58:24 | 显示全部楼层
贴出官方某高手的贴,,经测试ok
#include <FTPEx.au3>

$dir = '/4'
$server = '172.21.16.46'
$username = 'wwxsawis'
$pass = 'awis123'

$Open = _FTP_Open('test')
$Conn = _FTP_Connect($Open, $server, $username, $pass)
If Not @error Then ConsoleWrite('Connected!' & @CRLF)

_FTP_DirSetCurrent($Conn, '/StartDir/');Very Important to set the current dirctory to the directory that the folder you want to delete is in.
_FTPRemovedir($Conn, $dir)
_FTP_Close($Open)

Func _FTPRemovedir($l_FTPSession, $sFTPDirectory)
    Local $aFile, $hSearch, $sWorkingdir, $sFolderlist, $i, $bFirst, $aFolderStack[2] = [1, $sFTPDirectory]
    While $aFolderStack[0] > 0
        $sWorkingdir = $aFolderStack[$aFolderStack[0]]
        $aFolderStack[0] -= 1
        $aFile = _FTP_FindFileFirst($l_FTPSession, $sWorkingdir & '/*', $hSearch, $INTERNET_FLAG_NO_CACHE_WRITE)
        If Not @error Then
            $bFirst = True
            While 1
                If $bFirst = False Then
                    $aFile = _FTP_FindFileNext($hSearch)
                    If @error Then ExitLoop
                EndIf
                If $aFile[1] = 16 Then; If file is a directory we are going to add it to the stack of folders we need to go through
                    $aFolderStack[0] += 1
                    If UBound($aFolderStack) <= $aFolderStack[0] Then ReDim $aFolderStack[UBound($aFolderStack) * 2]
                    $aFolderStack[$aFolderStack[0]] = $sWorkingdir & "/" & $aFile[10]
                    $sFolderlist &= $sWorkingdir & "/" & $aFile[10] & ';'; Here I am adding the folder to a list of directorys I need to delete later
                Else; else we delete it
                    _FTP_FileDelete($l_FTPSession, $sWorkingdir & "/" & $aFile[10])
                    ConsoleWrite('File: ' & $sWorkingdir & "/" & $aFile[10] & ' Deleted' & @CRLF)
                EndIf
                $bFirst = False
            WEnd
        EndIf
        _FTP_FindFileClose($hSearch)
    WEnd
    $aFolderStack = StringSplit(StringTrimRight($sFolderlist, 1), ';')
    For $i = $aFolderStack[0] To 1 Step -1 ;Here we delete all those empty folders from last to first
        _FTP_DirDelete($l_FTPSession, $aFolderStack[$i])
        ConsoleWrite('Directory: ' & $aFolderStack[$i] & ' Deleted' & @CRLF)
    Next
    _FTP_DirDelete($l_FTPSession, $sFTPDirectory);Delete the original directory
EndFunc   ;==>_FTPRemovedir
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 21:26 , Processed in 0.082543 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表