delphi 遍历文件
///<summary>遍历文件</summary> ///<param>AList: 遍历所得文件列表,全路径</param> ///<param>APath: 遍历目录</param> ///<param>AExt: 遍历文件扩展名</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;