一种方法就是用我在上面说的FindFirst + FindNext 找一个删一个,另外,我给你找了一个函数,试了可以用:function DeleteFileEx(const AFileSrc: string): boolean; var fo : TSHFILEOPSTRUCT; begin FillChar(fo, SizeOf(fo), 0); with fo do begin Wnd := 0; wFunc := FO_DELETE; pFrom := PChar(AFileSrc); fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION; end; Result := (SHFileOperation(fo) = 0); end;函数出自:http://www.80diy.com/home/20011030/10/347282.html
我还想用个for语句 循环将一个一个文件删除呢 function DelFiles(FilePath:String): Boolean; var Find: TSearchRec; begin if (FindFirst(FilePath, faAnyFile, Find) = 0) then begin if Pos(FilePath,Find.Name)>0 then DeleteFile(FilePath+'\'+Find.Name); end; end; 谢谢 lihuasoft(一九七五) 你的思路我接受:)
function DelFiles(FilePath,FileName:String): Boolean; //FilePath:='C:\temp';FileName:='temp'; var Find: TSearchRec; begin SetCurrentDir(FilePath); if FindFirst('*',faArchive,Find) = 0 then begin repeat if Pos(FileName,Find.Name)>0 then DeleteFile(FilePath +'\' + Find.Name) until FindNext(Find) <> 0; FindClose(Find); end; end;//这样就实现了
var
fo : TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(AFileSrc);
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
end;
Result := (SHFileOperation(fo) = 0);
end;函数出自:http://www.80diy.com/home/20011030/10/347282.html
function DelFiles(FilePath:String): Boolean;
var
Find: TSearchRec;
begin
if (FindFirst(FilePath, faAnyFile, Find) = 0) then
begin
if Pos(FilePath,Find.Name)>0 then
DeleteFile(FilePath+'\'+Find.Name);
end;
end;
谢谢 lihuasoft(一九七五) 你的思路我接受:)
var
Find: TSearchRec;
begin
SetCurrentDir(FilePath);
if FindFirst('*',faArchive,Find) = 0 then
begin
repeat
if Pos(FileName,Find.Name)>0 then
DeleteFile(FilePath +'\' + Find.Name)
until FindNext(Find) <> 0;
FindClose(Find);
end;
end;//这样就实现了