Otro mas en trucomania...
-Añade 'ShellApi' en el uses de tu form
-Y utiliza esta función:
Código:
function ALaPapelera(Fichero:string):boolean;
var
FileOp: TSHFileOpStruct;
begin
if FileExists(Fichero)then
begin
FillChar(FileOp,SizeOf(FileOp),#0);
with FileOp do
begin
Wnd:= Application.Handle;
wFunc:= FO_DELETE;
pFrom:= PChar(Fichero+#0#0);
fFlags:= FOF_SILENT or FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
end;
Result:= (ShFileOperation(FileOp)=0);
end else
Result:=False;
end;
Un ejemplo de llamada:
Código:
procedure TForm1.Button1Click(Sender: TObject);
begin
if not ALaPapelera ('c:\kk\Fichero.txt') then
ShowMessage('No se pudo borrar el fichero/Can not delete file');
end;
Con una sóla llamada podemos tambien borrar más de un fichero. Se haría así:
Código:
procedure TForm1.Button1Click(Sender: TObject);
begin
if not ALaPapelera ('c:\kk\Fichero1.txt'+#0+'c:\windows\Fichero2.txt') then
ShowMessage('No se pudo borrar el fichero/Can not delete file');
end;
Simplemente separalos con un caracter 0 ( #0)
Para borrar un subdirectorio... pues sirve la misma función... por ejemplo:
ALaPapelera ('c:\UnDirectorio')