delphi 根据扩展名的文件搜索  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.06233286857605 seconds