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中操作olevariant、variant和stream

Delphi 判断素数的简单例子

Delphi synedit的安装和基本使用

Delphi unicode转换ansi

Delphi 把一个ico转换为bmp

Delphi 测试字符串读取类: tstringreader

Delphi监视注册表

Delphi多媒体函数

Delphi中对excel表格文件的导入和导出操作

apk权限大全 android必懂知识

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



打赏

取消

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

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

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

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

评论

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