可以使用 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;
Good Luck!