用FindFirst,FindNext,FindClose搜索该目录下的*.txt文件
对每个搜索结果使用DeleteFile
var
sr: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faAnyFile;
if FindFirst('c:/temp', FileAttrs, sr) = 0 then
begin
repeat
DeleteFile(sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
to emonster:
不用加系统检测了,注意我给出的完整语句是
if WinExec('command.com /c del c:/temp/*.txt',sw_hide)<31 then
WinExec('cmd.exe /c del c:/temp/*.txt',sw_hide);
to 孔明.net:
不会弹出窗口,因为我用了SW_HIDE参数
把shellapi加到interface下;
procedure TForm1.deleteClick(Sender: TObject);
//把d:/sybase目录下所有文件发送到回收站
var
sourcefile:STRING;
lpfileop:TSHFILEOPSTRUCT;
begin
sourcefile:= 'd:/sybase/*.*'+#0#0;
fillchar(lpfileop,sizeof(lpfileop),0);
with lpfileop do
begin
wnd:=form1.handle;
wFunc:=FO_DELETE;
pFrom:=pchar(sourcefile);
fflags:= FOF_ALLOWUNDO;
end;
if SHFileoperation(lpfileop)<>NOERROR then
if lpfileop. FAnyOperationsAborted then
showmessage('删除文件被终止')
else
showmessage('删除文件出错');
end;