Delphi2010新功能:TDirectory.GetFiles 支持通配符


本文整理自网络,侵删。

 
Delphi 2010 新增功能之: IOUtils 单元: TDirectory.GetFiles 支持通配符

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses IOUtils, Types;

const path = 'C:\Program Files\Embarcadero\RAD Studio\7.0';

//获取指定目录下有 Li 开头的文件
procedure TForm1.Button1Click(Sender: TObject);
var
  files: TStringDynArray;
  str: string;
begin
  files := TDirectory.GetFiles(path, 'Li*.*');
  Memo1.Clear;
  for str in files do Memo1.Lines.Add(str);
end;

//获取指定目录及其子目录下文件名只有 3 个字母的 pas 文件
procedure TForm1.Button2Click(Sender: TObject);
var
  files: TStringDynArray;
  str: string;
begin
  files := TDirectory.GetFiles(path, '???.pas', TSearchOption.soAllDirectories);
  Memo1.Clear;
  for str in files do Memo1.Lines.Add(str);
end;

end.


来源:http://blog.sina.com.cn/s/blog_3cb6a78c0100ityn.html

相关阅读 >>

Delphi执行cmd命令和bat文件

Delphi实现获取文件及文件夹大小(支持超过2g的大文件)

Delphi 校验注册码时的技巧

android实例-拍摄和分享照片、分享文本(xe8+小米2)

Delphi 处理链接和文件路径结尾\和/

Delphi xe5 给edit增加自定义按钮

Delphi检测程序内存泄漏

Delphi 获取内核地址的简单方法

Delphi xe firemonkey的stylebook皮肤控件的使用

Delphi winapi: loadstring - 从资源中载入字符串

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



打赏

取消

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

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

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

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

评论

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