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 判断 文本文件 utf-8 bom头

Delphi文本数据导入数据库的方法

Delphi isdirectory 判断是否是目录

Delphi 获取打印机纸型的例子

Delphi 判断特定字符是为单字节还是双字节

Delphi 判断按键状态

Delphi webbrowser1使用进度条查看浏览器状态

Delphi 网卡mac地址随机生成函数

Delphi splitter 控件属性及作用

Delphi try except与try finally不同之处

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



打赏

取消

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

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

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

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

评论

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