//用递归实现 procedure FindNewToOld(Dir: string); var sr: TSearchRec; begin if FindFirst(Dir+'\*.*', faAnyFile, sr) = 0 then begin repeat if ((sr.Attr and faDirectory)=faDirectory) and(sr.Name<>'.') and (sr.Name<>'..') then FindNewToOld(Dir+'\'+sr.Name) else if (sr.Name <>'.') and (sr.Name<>'..') then //你的处理文件的函数或过程 until FindNext(sr) <> 0; FindClose(sr); end; end;调用FindNewToOld('c:\mydir');
procedure FindNewToOld(Dir: string);
var sr: TSearchRec;
begin
if FindFirst(Dir+'\*.*', faAnyFile, sr) = 0 then
begin
repeat
if ((sr.Attr and faDirectory)=faDirectory) and(sr.Name<>'.') and (sr.Name<>'..') then
FindNewToOld(Dir+'\'+sr.Name)
else if (sr.Name <>'.') and (sr.Name<>'..') then
//你的处理文件的函数或过程
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;调用FindNewToOld('c:\mydir');