domingo, 31 de maio de 2009

Dicas Delphi - Apagando um Subdiretório

Inclua a unit SHELLAPI na clausula uses do seu form.

procedure DeleteDir( hHandle : THandle; Const sPath : String );
var
OpStruc: TSHFileOpStruct;
FromBuffer, ToBuffer: Array[0..128] of Char;
begin
fillChar( OpStruc, Sizeof(OpStruc), 0 );
FillChar( FromBuffer, Sizeof(FromBuffer), 0 );
FillChar( ToBuffer, Sizeof(ToBuffer), 0 );
StrPCopy( FromBuffer, sPath);
With OpStruc Do
Begin
Wnd:= hHandle;
wFunc:=FO_DELETE;
pFrom:= @FromBuffer;
pTo:= @ToBuffer;
fFlags:= FOF_NOCONFIRMATION;
fAnyOperationsAborted:=False;
hNameMappings:=nil;
//lpszProgressTitle:=nil;
End;
ShFileOperation(OpStruc);
end;


// Utilize a função assim:

procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteDir( Self.Handle,'C:\Temp');
end;

Nenhum comentário: