Buscar

Deletando um diretório

Código

Procedure DelTree(const RootDir : String);
var
SearchRec : TSearchRec;
begin
Try
ChDir(RootDir); {Caminho Especificado}
FindFirst('*.*',faAnyFile,SearchRec);
Erc := 0;
while Erc = 0 do
begin
if ((SearchRec.Name <> '.' ) and (SearchRec.Name <> '..')) then
begin
if (SearchRec.Attr and faDirectory>0) then
begin
{Achou o diretório e ira apagar seus arquivos}
DelTree(SearchRec.Name);
end
else
begin
{Achou um arquivo. Apagar ou não}
end;
end;
Erc := FindNext (SearchRec);
{ Erc igual a zero se o FindNext obtiver sucesso, senão erro do DOS}
Application.ProcessMessages;
end;
finally
if Length(RootDir) > 3 then
ChDir('..');
end;
end;

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Arquivos
Adicionada dia: 11/06/03
Por: Felipe Monteiro
Visualizada: 2571 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009