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 tstringlist 保存txt文本文件最后一行不留空行

Delphi tidhttpserver开发http服务端外网无法访问

Delphi2010中Delphi class explorer妙用

Delphi读取utf8格式ini及取得动态�热�

Delphi使用spcomm没办法触发receivedata

Delphi copy 从字符串中复制指定范围中的字符

Delphi extractclassname 字符串处理函数

Delphi mscomm 发送接收

Delphi程序将自身可执行文件拷贝到u盘的代码

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



打赏

取消

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

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

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

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

评论

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