Jump to content
Sign in to follow this  

problem with my FTPDelDirRecursive function

Recommended Posts


First, Sorry for my bad english, I'm french.

I have write a function who delete all files and directory in a specified directory on FTP server.

But I have a problem, the loop don't work, Can you look my code ?

Code :

#include "ftp3.au3"

$server = 'my_ftp_server'
$username = 'my_username'
$pass = 'my_password'
$ftp_main_dir = '/exemple/'
$ftp_file_mask = '*.*'

$dllhandle = DllOpen('wininet.dll')
$Open = _FTPOpen('MyFTP Control')
If @error Then MsgBox(0, "error", "Open")
$Conn = _FTPConnect($Open, $server, $username, $pass)
If @error Then MsgBox(0, "error", "Connect")

Func FTPDelDirRecurse($ftp_dir)

        Dim $Handle
        Dim $DllRect
        Local $FileInfo = _FtpFileFindFirst($Conn, $ftp_dir & $ftp_file_mask, $Handle, $DllRect)
        If $FileInfo[0] Then
;~         If current is directory
                If $FileInfo[1] == 16 And $FileInfo[10] <> "." And $FileInfo[10] <> ".." Then ; dir attrib = 16
                    MsgBox(0, "Current dir", $FileInfo[10])
                    Local $i = $ftp_dir & $FileInfo[10] & "/"
;~     If current is file
                If $FileInfo[1] == 128 Then ; file attrib = 128
                    MsgBox(0, "Current file", $FileInfo[10])
                    _FTPDelFile($Conn, $ftp_dir & $FileInfo[10])
                $FileInfo = _FtpFileFindNext($Handle, $DllRect)
            Until Not $FileInfo[0]   
        _FtpFileFindClose($Handle, $DllRect)
EndFunc ;==> FTPDelDirRecurse
Edited by NeuroToxic

Share this post

Link to post
Share on other sites

Don't use DIM anywhere anymore. Declare explicitly for Global or Local. Specifically, change DIM to Local inside your function. I can't test, so I don't know if that impacts your function, but it stood out.

Also, everything your function needs from the global environment should be passed to it, not read from Global variables. You should pass $Conn and $ftp_file_mask as parameters (re-passing them in the recursive calls).

Third, is the mask "*.*" appropriate for what you want? I would have expected just "*" for FTP.

Hope that helps.


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...