如何将文件丢到回收站?(100分)

  • 主题发起人 主题发起人 tr
  • 开始时间 开始时间
可以使用 SHFileOperation(), 值得注意的是档名 list 中是以 #0 分隔, 最後一个项目
必须以双 #0 字元结束, 以下分别是删除整个目录(含字目录) 与档案的用法示例:
// Test for delete a folder and move files into Recycle Bin
// Change the APath variable as you need.
// uses ..., ShellAPI;
procedure TForm1.Button1Click(Sender: TObject);
var
APath : AnsiString;
lpFileOp: TSHFileOpStruct;
begin
APath := 'D:/temp/test123'#0#0;
// must end withdo
uble-#0
with lpFileOpdo
begin
Wnd := Self.Handle;
wFunc := FO_DELETE;
pFrom := pchar(APath);
pTo := nil;
fFlags := FOF_ALLOWUNDO;
hNameMappings := nil;
lpszProgressTitle := nil;
fAnyOperationsAborted := True;
end;

if SHFileOperation(lpFileOp) = 0 then
ShowMessage('SHFileOperation OK.')
else
ShowMessage('SHFileOperation Fail!!');
end;

档案s 删除并送至资源回收筒?
procedure TForm1.Button1Click(Sender: TObject);
var
APath : AnsiString;
lpFileOp: TSHFileOpStruct;
begin
// must end withdo
uble-#0
APath :=
'D:/temp/test123/l.txt'#0'D:/temp/test123/l3.txt'#0#0;
with lpFileOpdo
begin
Wnd := Self.Handle;
wFunc := FO_DELETE;
pFrom := pchar(APath);
pTo := nil;
fFlags := FOF_ALLOWUNDO;
hNameMappings := nil;
lpszProgressTitle := nil;
fAnyOperationsAborted := True;
end;

if SHFileOperation(lpFileOp) = 0 then
ShowMessage('SHFileOperation OK.')
else
ShowMessage('SHFileOperation Fail!!');
end;
 
接受答案了.
 
后退
顶部