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.