本文整理自网络,侵删。
procedure DoEnumAllFiles(strPath: string;FileList: TStrings);{功能:枚举指定目录及子目录下的所有文件}var sr: TSearchRec;
begin if strPath = '' then Exit;
strPath := IncludeTrailingPathDelimiter(strPath);
if not DirectoryExists(strPath) then Exit;
if FindFirst(strPath + '*.*', System.SysUtils.faAnyFile, sr) = 0 then begin try repeat //非目录的,就是文件 if (sr.Attr and System.SysUtils.faDirectory = 0 ) then begin FileList.Add(strPath + sr.Name); end; until FindNext(sr) <> 0; finally System.SysUtils.FindClose(sr); end; end;
//查找子目录。 if FindFirst(strPath + '*', System.SysUtils.faDirectory, sr) = 0 then begin try repeat if (sr.Attr and System.SysUtils.faDirectory<>0) and (sr.Name<>'.') and (sr.Name<>'..') then begin DoEnumAllFiles(strPath + sr.Name, FileList); end; until FindNext(sr) <> 0; finally FindClose(sr); end; end;
end;
相关阅读 >>
Delphi xe2 - 万一“获取程序自身大小的函数”改进版
Delphi stringgrid 实例2:1、获取 stringgrid 的行数、列数; 2、给单元赋值
Delphi 颜色转换函数: 从 Delphi 到 html
更多相关阅读请进入《Delphi》频道 >>