Excluir todos os arquivos e pastas de forma recursiva usando o Delphi
Eu estou tentando excluir uma pasta e todas as suas subpastas recursivamente, mas não está funcionando, então alguém pode, por favor, verificar o código e me dizer o que estou fazendo de errado aqui?
Eu estou executando este código através do D7 no Windows XP
if FindFirst (FolderPath + '\*', faAnyFile, f) = 0 then
try
repeat
if (f.Attr and faDirectory) <> 0 then
begin
if (f.Name <> '.') and (f.Name <> '..') then
begin
RemoveDir(FolderPath +'\'+ f.Name);
end
else
begin
//Call function recursively...
ClearFolder(FolderPath +'\'+ f.Name, mask, recursive);
end;
end;
until (FindNext (f) <> 0);
finally
SysUtils.FindClose (f)
end;
end;