05-04-2012، 11:56 AM
با تابع زیر که با دلفی نوشته شده است میتونید فایل مورد نظر خودتون رو از سطل زباله پاک کنید.
english :
This tip was contributed by Dave Johnson who, after searching the net for a delete function finally found one he had written himself some time previously! A nice little routine, and extremely useful, so thanks to Dave for this one...
english :
This tip was contributed by Dave Johnson who, after searching the net for a delete function finally found one he had written himself some time previously! A nice little routine, and extremely useful, so thanks to Dave for this one...
کد:
function myDeleteFile(Filename : string; ToRecycle : Boolean) : Boolean;
var
tempFileOp : TSHFileOpStruct;
begin
if FileExists(Filename) then
begin
with tempFileOp do
begin
Wnd:=0;
wFunc:=FO_DELETE;
pFrom:=pchar(Filename+#0+#0); // Must be double #0 to terminate the string.
// WARNING: Documented, but UNTESTED by me.
// You can use a single #0 to seperate multiple
// files in a single call.
pTo:=#0+#0; // Prevents Crash in D5 and maybe beyond
if ToRecycle then
fFlags:=FOF_FILESONLY or FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_SILENT
else
fFlags:=FOF_FILESONLY or FOF_NOCONFIRMATION or FOF_SILENT;
SHFileOperation(tempFileOp);
end;
end;
Result:=not(FileExists(Filename));
end;