Problemas para deletar um diretório com subdiretórios? Utilize a função abaixo:
uses
Shellapi, filectrl, //declare estas das units!!!
function DeleteFolder(FolderName: string; LeaveFolder: Boolean): Boolean;
var
r: TshFileOpStruct;
begin
Result := False;
if not DirectoryExists(FolderName) then
Exit;
if LeaveFolder then
FolderName := FolderName + ' *.* '
else
if FolderName[Length(FolderName)] = ' \ ' then
Delete(FolderName,Length(FolderName), 1);
FillChar(r, SizeOf(r), 0);
r.wFunc := FO_DELETE;
r.pFrom := PChar(FolderName);
r.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
Result := ((ShFileOperation(r) = 0) and (not r.fAnyOperationsAborted));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteFolder('c:\temp',false);
end;
Take care
Nenhum comentário:
Postar um comentário