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 unigui form控件跳转

Delphi 获取网页代码单元

Delphi判断系统是否安装tcp/ip协议

Delphi firedac压缩和修复ms access数据库

Delphi 获取当前系统版本号

Delphi xe android platform uses-permission[2] androidmanifest.xml 配置

Delphi 中的包开发

Delphi中自适应窗体的实现

Delphi 安装apk

Delphi使用spcomm串口通信 串口号大于10出错的解决办法

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



打赏

取消

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

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

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

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

评论

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

    暂无评论...