procedure DeleteFolderRecursive(hFTP: HINTERNET; Path:
String);
var
hSearch: HINTERNET;
findData: WIN32_FIND_DATA;
TempList: TStringList;
i: Integer;
begin
TempList := TStringList.Create;
try
hSearch := FtpFindFirstFile(hFTP,PChar(GetFolderPath(Path)),findData,0,0);
repeat
if findData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY
then
begin
if not FtpRemoveDirectory(hFTP, PChar(GetFolderPath(Path)))
then
begin
TempList.Add(Path + findData.cFileName + '
\');
end;
end
else
begin
if not FtpDeleteFile(hFTP, PChar(GetFolderPath(Path) + findData.cFileName))
then
Main_Extras.ErrorPrint('
Could not delete File ' + Path + findData.cFileName + '
.', '
FTP File Delete Error');
end;
until not InternetFindNextFile(hSearch,@findData);
InternetCloseHandle(hSearch);
for i:=0
to TempList.Count-1
do
begin
DeleteFolderRecursive(hFTP, TempList[i]);
if not FtpRemoveDirectory(hFTP, PChar(GetFolderPath(TempList[i])))
then
Main_Extras.ErrorPrint('
Could not delete Folder ' + TempList[i] + '
.', '
FTP Folder Delete Error');
end;
finally
TempList.Free;
end;
end;