delphi XE 枚举指定目录及子目录下的所有文件


本文整理自网络,侵删。

 
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 建立access数据库

Delphi pi 精确计算返回圆周率

Delphi 对gzip解压

Delphi 操作系统时间与web标准时间校正

Delphi 模似键盘输入又一方法

Delphi 单击按钮左键弹起菜单

Delphi datasnap清除僵死连接

Delphi 和微软的 azure 云存储

Delphi 禁止改变窗口大小和移动窗口

Delphi 虚拟桌面原理及实现

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...