procedure ProcessAFile;
begin
if (info.Name<>'.') and (info.Name<>'..') and ((info.Attr and faDirectory)<>faDirectory) then
begin
if assigned(proc) then
proc(fpath+info.FindData.cFileName,info,quit,bsub);
end;
end;
procedure ProcessADirectory;
begin
if (info.Name<>'.') and (info.Name<>'..') and ((info.attr and fadirectory)=fadirectory) then
findfile(quit,fpath+info.Name,filename,proc,bsub,bmsg);
end;
begin
if path[length(path)]<>'\' then
fpath:=path+'\'
else
fpath:=path;
try
if 0=findfirst(fpath+filename,faanyfile and (not fadirectory),info) then
begin
ProcessAFile;
while 0=findnext(info) do
begin
ProcessAFile;
if bmsg then application.ProcessMessages;
if quit then
begin
findclose(info);
exit;
end;
end;
end;
finally
findclose(info);
end;
try
if bsub and (0=findfirst(fpath+'*',faanyfile,info)) then
begin
ProcessADirectory;
while findnext(info)=0 do
ProcessADirectory;
end;
finally
findclose(info);
end;
end;
例子:
procedure aaa(const filename:string;const info:tsearchrec;var quit,bsub:boolean);
begin
form1.listbox1.Items.Add(filename);
quit:=form1.qqq;//qqq为form1的自定义boolean变量
bsub:=form1.checkbox1.Checked;
end;
procedure FindAllFile(FPath:String);
var sr: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile;
if FindFirst(FPath+'*.txt', FileAttrs, sr) = 0 then begin
repeat
//是目录
if ((sr.Attr and faDirectory) = faDirectory)
and (sr.Name<>'.') and (sr.Name<>'..') then begin
FindAllFile(FPath+sr.Name+'\');
end else begin
//是文件
slTemp.Add(FPath+sr.Name);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
是可以实现的,学习...
procedure FindAllFile(FPath:String);
var sr: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile;
if FindFirst(FPath+'*.txt', FileAttrs, sr) = 0 then begin
repeat
//是目录
if ((sr.Attr and faDirectory) = faDirectory)
and (sr.Name<>'.') and (sr.Name<>'..') then begin
FindAllFile(FPath+sr.Name+'\');
end else begin
//是文件
slTemp.Add(FPath+sr.Name);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;