procedure TForm1.ShellListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
T: TSHFileOpStruct;
begin
if key=32 then
begin
T.Wnd:=0;
T.wFunc:=FO_DELETE;
//T.fFlags := FOF_ALLOWUNDO+FOF_NOERRORUI+FOF_NORECURSION;
T.pFrom:=PChar(ShellListView1.selectedfolder.PathName);
if FileExists(ShellListView1.SelectedFolder.PathName) then
begin
DeleteFile(ShellListView1.selectedfolder.PathName);
ShellListView1.Refresh;
end else
SHFileOperation(T);
end;
end;上面的代码完不了,哪位帮改一下?
Shift: TShiftState);
var
T: TSHFileOpStruct;
begin
if key=32 then
begin
T.Wnd:=0;
T.wFunc:=FO_DELETE;
//T.fFlags := FOF_ALLOWUNDO+FOF_NOERRORUI+FOF_NORECURSION;
T.pFrom:=PChar(ShellListView1.selectedfolder.PathName);
if FileExists(ShellListView1.SelectedFolder.PathName) then
begin
DeleteFile(ShellListView1.selectedfolder.PathName);
ShellListView1.Refresh;
end else
SHFileOperation(T);
end;
end;上面的代码完不了,哪位帮改一下?
看了下MSDN,解释大致是这样的
TShFileOpStruct结构中的from和to路径都是可以使用多个文件名的,SHFileOperation函数判断一个文件名的结束是用#0为依据,如果光是这样的话,它就没法知道什么时候文件列表结束了,所以以两个#0作为整个列表的结束符。
T: TSHFileOpStruct;
begin
FillChar(T, Sizeof(T), 0);
T.Wnd:=0;
T.wFunc:=FO_DELETE;
T.fFlags :=FOF_NOCONFIRMATION;
T.fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR+FOF_NOERRORUI;
T.pFrom:=PChar(ShellListView1.selectedfolder.PathName + #0);
if FileExists(ShellListView1.SelectedFolder.PathName) then
begin
DeleteFile(ShellListView1.selectedfolder.PathName)
end else
SHFileOperation(T);
ShellListView1.Refresh;
end;