Buscar

Deletando um diretório via delphi

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: Windows
Adicionada dia: 20/12/03
Por: Cláudio F. Pirasol
Visualizada: 6053 vezes

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