每日程炼-IOUtils单元3查找并搜索文件夹信息

  • A+
所属分类:[开发技巧]

实现查收指定目录的,特定文件名和 模糊查询也能很简单实现

获取指定目录下有 Li 开头的文件

获取指定目录及其子目录下文件名只有 3 个字母的 pas 文件

DEMO下载:IOUnit3

 

代码部分: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) mmo1: TMemo; btn1: TButton; btn2: TButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses IOUtils, Types; const path = 'D:\Program Files\Embarcadero\RAD Studio\7.0'; //获取指定目录下有 Li 开头的文件 procedure TForm1.btn1Click(Sender: TObject); var files: TStringDynArray; str: string; begin files := TDirectory.GetFiles(path, 'Li*.*'); mmo1.Clear; for str in files do mmo1.Lines.Add(str); end; //获取指定目录及其子目录下文件名只有 3 个字母的 pas 文件 procedure TForm1.btn2Click(Sender: TObject); var files: TStringDynArray; str: string; begin files := TDirectory.GetFiles(path, '???.pas', TSearchOption.soAllDirectories); mmo1.Clear; for str in files do mmo1.Lines.Add(str); end; end.   窗体部分: object Form1: TForm1 Left = 0 Top = 0 Caption = #24858#20154#31508#35760'-http://www.codefool.com' ClientHeight = 291 ClientWidth = 476 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object mmo1: TMemo Left = 0 Top = 0 Width = 473 Height = 201 ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861 Lines.Strings = ( 'mmo1') TabOrder = 0 end object btn1: TButton Left = 136 Top = 220 Width = 193 Height = 25 Caption = #33719#21462#25351#23450#30446#24405#19979#26377' Li '#24320#22836#30340#25991#20214 TabOrder = 1 OnClick = btn1Click end object btn2: TButton Left = 64 Top = 251 Width = 337 Height = 25 Caption = #33719#21462#25351#23450#30446#24405#21450#20854#23376#30446#24405#19979#25991#20214#21517#21482#26377' 3 '#20010#23383#27597#30340' pas '#25991#20214 TabOrder = 2 OnClick = btn2Click end end

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: