delphi 搜索指定目录下的文件


本文整理自网络,侵删。

 修改FindFirst(Directory+'\*.*', $0000003F, SearchRec) = 0 中的

"\*.*"部分即可找到你所需要的特定文件

例如:\*.txt 表示搜索搜索指定目录下的txt文件




unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Memo1: TMemo;
Label2: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

Function FindAllFileInADirectory(Directory:string;RetList : TStringList): TStringList;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Text:='';
end;


Function TForm1.FindAllFileInADirectory(Directory:string;RetList:TStringList): TStringList;
var
SearchRec: TSearchRec;
begin
if FindFirst(Directory+'\*.*', $0000003F, SearchRec) = 0 then
begin
repeat
RetList.Add(Directory +'\'+ SearchRec.Name);
until (FindNext(SearchRec) <> 0);
end;
FindClose(SearchRec);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
TempList:TStringList;
begin
TempList:=TStringList.Create;
TempList:=FindAllFileInADirectory(Edit1.text,TempList);
memo1.Lines.Clear;
memo1.Lines.Assign(TempList);
TempList.clear;
end;

end. //end unit

相关阅读 >>

Delphi写的一个屏幕截取函数

Delphi 利用google api生成二维码图像

Delphi idpop3收邮件

dbgrideh 组件在borland开发工具中应用全攻略

Delphi键盘按键伪码多类型

monthoftheyear:取得一个tdatetime变量的月份在年度中的索引

Delphi 解析json生成json

Delphi webbrowser 无法调用当前浏览器的版本

Delphi canvas.lineto 画线

Delphi 让socket支持域名上线

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



打赏

取消

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

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

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

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

评论

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