这是我以前编写的,使用ShellFileRemove()删除文件或目录到回收站中:
ShellFileRemove(0, 'c:/windows/temp', False)
uses ..., ShellAPI;
//******************************************************************************
// 功能:Shell文件操作-通用
//******************************************************************************
function ShellFileOperation(Owner:HWND; const FromFile, ToFile: string;
Op, Flags: Word):Boolean;
Var
FileStruct : TSHFileOpStruct;
s1, s2 : string;
begin
s1 := FromFile + #0#0;
s2 := ToFile + #0#0;
With FileStruct do
Begin
Wnd := Owner;
wFunc := op;
pFrom := PChar(s1);
pTo := PChar(s2);
fFlags := Flags;
hNameMappings :=nil;
lpszProgressTitle :=nil;
fAnyOperationsAborted := False;
End;
Result:= (SHFileOperation(FileStruct)=0)
and (not FileStruct.fAnyOperationsAborted);
end;
//******************************************************************************
// 功能:Shell文件操作-删除
//******************************************************************************
function ShellFileRemove(Owner:HWND; const FileOrDir: string; Confirm: Boolean): Boolean;
var
Flag: WORD;
begin
Flag:= FOF_ALLOWUNDO;
if not Confirm then Flag:= Flag or FOF_NOCONFIRMATION;
Result:= ShellFileOperation(Owner, FileOrDir, #0, FO_DELETE, Flag);
end;