Delphi 根据扩展名的文件搜索


本文整理自网络,侵删。

 
procedure GetAllFilesEM(Path, ExtMask: String; List: TStrings;
  SubFolder: Boolean);
var
 Attrib, k: Integer;
 Search: TSearchRec;
begin
 Attrib := faArchive + faReadOnly + faHidden;

 if Path[Length(Path)] <> '\' then Path := Path + '\';

 with TStringList.Create do
 try
   CommaText := ExtMask;

   for k := 0 to Count - 1 do
   if FindFirst(Path + '*.' + Strings[k], Attrib, Search) = 0 then
     repeat
       List.Add(AnsiUpperCase(Path + Search.Name));
     until FindNext(Search) <> 0;

   FindClose(Search);
 finally Free end;

 if SubFolder then
 begin
   if FindFirst(Path + '*.*', faDirectory, Search) = 0 then
   begin
     repeat
       if ((Search.Attr and faDirectory) = faDirectory) and
         (Search.Name[1] <> '.') then
         GetAllFilesEM(Path + Search.Name, ExtMask, List, SubFolder);
         Application.ProcessMessages ;
     until FindNext(Search) <> 0;

     FindClose(Search);
   end;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetAllFilesEM('d:\', '*.py', Memo1.Lines, True);
end;

相关阅读 >>

Delphi 泛型数组 strsplit 字符串分割

Delphi旋转位图

Delphi 清除字符串两边空格或指定字符

Delphi模仿“千千静听”滚动标题栏,非常简单!

Delphi drawing text 绘制文本

Delphi 流与字符串

Delphi tbitmap 位图组件

Delphi access数据库密码的mdb的访问报错“无法启动应用程序,或是已被其他用户已独占方式打开”

Delphi webservices base64编码

Delphi ioutils 获取当前目录下所有的文件/文件夹

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



打赏

取消

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

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

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

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

评论

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