How to delete directories containing sub directories and files on an FTP server in Delphi?

0

I've been trying to get my Delphi 2010 application to remove a directory on an FTP server, I've used TIdFTP for this task with the "RemoveDir" command, but the process fails, because according to the application the directory does not is empty. What can I do to solve my problem?

    
asked by anonymous 02.02.2018 / 15:28

1 answer

1

As far as I know, Indy does not have a "ready" method for what it wants. You will have to create a recursive method to delete all files and subdirectories before removing the root directory. See this example below adapted from a code obtained at progtown.com a>:

procedure FTPRemoveDir(Dir: string);
var
  I: Integer;
  List: TStringList;
begin
  List := TStringList.Create;
  try
    FTP.ChangeDir(Dir);
    FTP.List(List, '', false);
    for i := 0 to List.Count - 1 do
    begin
      if FTP.Size(List[I]) = -1 then
        DelFTPDir(List[I])
      else
        FTP.Delete(List[I]);
    end;
    FTP.ChangeDirUp;
    FTP.RemoveDir(Dir);
  finally
    List.Free;
  end;
end;

I hope I have helped! Hugs!

    
14.02.2018 / 20:21