Jump to content

_FTP_DirDelete not deleting DIR's with spaces


Recommended Posts

Hello everyone,

I've searched the forums and google and couldn't find anything on this issue other than to enclose the file path in quotes. MSDN makes no mention of spaces being an issue...

That said, when I try to delete an FTP folder with spaces in it, the folder will not delete. Here is the relevant part of the script (I'm recursively deleting a folder).

Func _FTPRemovedir($l_FTPSession, $sFTPDirectory)
    $rmdirgui = GUICreate("Deleting folder: " & $sFTPDirectory, 300, 200, -1, -1, -1, $WS_DLGFRAME)
    $rmdirtext = GUICtrlCreateInput("", 10, 10, 280, 180, $ES_MULTILINE + $ES_READONLY)
    GUISetState()
    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
                    If $aFile[10] <> ".." And $aFile[10] <> "." Then
;~                      If StringInStr($aFile[10], " ") Then $aFile[10] = StringReplace($aFile[10], " ", "_")
                        $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
                    EndIf
                Else; else we delete it
                    If StringInStr($aFile[10], "/./") = 0 And StringInStr($aFile[10], "/../") = 0 Then
                        _FTP_FileDelete($l_FTPSession, $sWorkingdir & "/" & $aFile[10])
                        GUICtrlSetData($rmdirtext, @CRLF & 'File: ' & $sWorkingdir & "/" & $aFile[10] & ' Deleted', "add")
                    Else
                        GUICtrlSetData($rmdirtext, @CRLF & 'File: ' & $sWorkingdir & "/" & $aFile[10] & ' Skipped (In higher DIR)', "add")
                    EndIf
                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]) ;<--- This is the problem area.
;~      _FTP_Command($l_FTPSession, 'rmdir ' & $aFolderStack[$i])
        GUICtrlSetData($rmdirtext, @CRLF & 'Directory: ' & $aFolderStack[$i] & ' Deleted', "add") 
    Next
    _FTP_DirDelete($l_FTPSession, $sFTPDirectory);Delete the original directory
    GUIDelete($rmdirgui)
EndFunc   ;==>_FTPRemovedir
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...