PDA

View Full Version : سوال: چگونه می توان یک فایل را حذف کرد و آن را به Recycle Bin منتقل کرد؟



drahmadtaraffoo
چهارشنبه 25 اسفند 1389, 09:31 صبح
بسم الله الرحمن الرحیم
با سلام خدمت دوستان عزیز
چگونه می توان یک فایل را حذف کرد و آن را به Recycle Bin منتقل کرد؟
البته با دستور زیر می توان فایل را حذف نمود؛ اما به Recycle Bin منتقل نمی شود.
;(DeleteFile(َAdressFile
:تشویق: متشکرم :تشویق:

seyed_farid
چهارشنبه 25 اسفند 1389, 13:29 عصر
-Add 'ShellApi' in the uses of your form
-And use this function:



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;
================================================== =======

A call example:


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;



Update from 08/08/99:

With a single call, we can delete two or more files. For example:



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;



Simply separate them with a 0 character ( #0 )




ALaPapelera ('c:\UnDirectorio');