我想一次删除多个文件,要如何写呢?如下是只能删一个文件
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
end;procedure TForm1.Button2Click(Sender: TObject);
var
OpStruct :TSHFileOpStruct;
begin
//设置OpStruc
with OpStruct do
begin
Wnd := Form1.Handle;
wFunc := FO_DELETE;
pFrom := PChar(Edit1.Text);
fFlags := FOF_ALLOWUNDO;
end;
SHFileOperation(OpStruct);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
end;procedure TForm1.Button2Click(Sender: TObject);
var
OpStruct :TSHFileOpStruct;
begin
//设置OpStruc
with OpStruct do
begin
Wnd := Form1.Handle;
wFunc := FO_DELETE;
pFrom := PChar(Edit1.Text);
fFlags := FOF_ALLOWUNDO;
end;
SHFileOperation(OpStruct);
end;
var
DeleteFileName:String;
OpStruc:TSHFileOpStruct;
i:Integer;
begin
for i:=CheckListBox1.Count-1 downto 0 do
if CheckListBox1.Checked[i] then
begin
DeleteFileName:=CheckListBox1.Items.Strings[i];
with OpStruc do
begin
Wnd:=Application.Handle;
wFunc:=FO_DELETE;
pFrom:=PChar(DeleteFileName+#0#0);
pTo:=PChar(#0#0);
fFlags:=FOF_ALLOWUNDO or FOF_NoConfirmation;
end;
SHFileOperation(OpStruc);
end;
CheckListBox;
end;procedure TForm1.Button7Click(Sender: TObject);
var
DeleteFileName:String;
OpStruc:TSHFileOpStruct;
i:Integer;
begin
if (MessageBox(handle,'删除后不能恢复!真的要删除吗?','提示',MB_OKCANCEL+MB_ICONQUESTION)=1) then
begin
for i:=CheckListBox1.Count-1 downto 0 do
if CheckListBox1.Checked[i] then
begin
DeleteFileName:=CheckListBox1.Items.Strings[i];
with OpStruc do
begin
Wnd:=Application.Handle;
wFunc:=FO_DELETE;
pFrom:=PChar(DeleteFileName+#0#0);
pTo:=PChar(#0#0);
fFlags:=FOF_NoConfirmation;
end;
SHFileOperation(OpStruc);
end;
CheckListBox;
end;
end;