///<summary> traverse file </summary>///<param>alist: Traverse the resulting file list, Full path </param>///<param>apath: Traverse directory </param>///<param>aext: Traverse file extension </param>procedure Gfilelist (alist:tstringlist; const Apath, aext:string); var str:string; Sch:tsearchrec;begin If alist = nil then Exit; Alist.clear; str: = Trim (Apath); If Rightstr (str, 1) <> "then str: = str + ' \ '; If not directoryexists (str) then Exit; If Sysutils.findfirst (str + ' * ', faanyfile, Sch) = 0 THEN begin repeat application.processmessages; if (Sch. Name = '. ') or (Sch. Name = '.. ')) Then Continue; If directoryexists (str + sch. Name) then gfilelist (alist, str + sch. Name, Aext) ELSE BEGIN if (Uppercase (Extractfileext (str + sch). Name) = uppercase (Aext)) or (aext= '. * ') then Alist.add (str + sch. Name); End Until FindNext (Sch) <> 0; Sysutils.findclose (Sch); End;end;
Delphi Traversal File