本文整理自网络,侵删。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
found:integer;
dirstr:string;
keyword:string;
rc:TSearchRec;
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
dirstr:='c:\windows\'; //任意目录
keyword:='*.exe'; //关键字
s:=dirstr+Trim(keyword); //网上说去与结果不符的项 例如 _.exe~ 等等
found:=findfirst(s,faAnyFile,rc);
while found=0 do
begin
if (rc.Attr and faDirectory) <> 0 then // 判断目录
found:=FindNext(rc)
else
begin
listbox1.Items.Add(rc.Name); //do samething...
found:=FindNext(rc);
end
end;
end;
end.
相关阅读 >>
Delphi mediaplayer android 下播放 mp4 的问题
Delphi firemonkey处理图形的方式与vcl处理图形的方式大不相同
Delphi 利用windows api判断文件共享锁定状态
Delphi d10.x 并行库ppl编程之 futures
更多相关阅读请进入《Delphi》频道 >>