Delphi 如何使用FindFirst搜索不同的文件类型?


本文整理自网络,侵删。

 
procedure FileSearch(const PathName: string; const Extensions: string;
 var lstFiles: TStringList);
const
  FileMask = '*.*';
var
  Rec: TSearchRec;
  Path: string;
begin
  Path := IncludeTrailingBackslash(PathName);
  if FindFirst(Path + FileMask, faAnyFile - faDirectory, Rec) = 0 then
    try
      repeat
        if AnsiPos(ExtractFileExt(Rec.Name), Extensions) > 0 then
          lstFiles.Add(Path + Rec.Name);
      until FindNext(Rec) <> 0;
    finally
      SysUtils.FindClose(Rec);
    end;

  if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
    try
      repeat
        if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name <> '.') and
          (Rec.Name <> '..') then
          FileSearch(Path + Rec.Name, Extensions, lstFiles);
      until FindNext(Rec) <> 0;
    finally
      FindClose(Rec);
    end;
end;

用法:
FileSearch('C:\Temp', '.txt;.tmp;.exe;.doc', FileList);

相关阅读 >>

Delphi 获得idhttp redirect后的url

Delphi字符串拆分(字符数限制)

Delphi 如何确定活动桌面是否已启用

Delphi 取出一个字符在字符串出现的次数

Delphi线程中关闭程序

Delphi屏蔽win、ctrl_esc、alt_tab、alt_f4等键(windows xp、windows 2003 server下测试通过)

Delphi winapi: settimer、killtimer - 创建与移除高性能定时器

Delphi tfilestream 的读写 合并文件

Delphi 10.3 断点调试相关快捷键

Delphi idhttp登录网站教程代码

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



打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...