unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, ComCtrls, StdCtrls, Db, ADODB;type
  TForm1 = class(TForm)
    tv: TTreeView;
    SpeedButton1: TSpeedButton;
    Edit1: TEdit;
    ADOCommand1: TADOCommand;
    ADODataSet1: TADODataSet;
    procedure SpeedButton1Click(Sender: TObject);
  private
    procedure  AddTv(const path1:string;Node:TTreeNode);
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}{ TForm1 }procedure TForm1.AddTv(const path1: string; Node: TTreeNode);
var
  i:integer;
  Sr:TsearchRec;
  findNode:TTreeNode;
  path:string;
begin
  path:=Path1;
  if  Path[Length(Path)]<>'\' then
    Path:=Path+'\*.*'
  else Path:=Path+'*.*';  if findfirst(Path,faanyfile,sr)=0 then
  begin
    repeat
      if (sr.Attr and faDirectory)=faDirectory then//目录
        if (sr.Name ='.') or(sr.Name ='..' )then
            continue
         else
         begin
           FindNode:=tv.Items.AddChildFirst(node,sr.name);
           //path:=copy(path,1,length(path)-3);//去掉*。*
           //path:=path+sr.Name;
           path:=Path1;
           if  Path[Length(Path)]<>'\' then
              path:=path+'\';
           AddTv(path+sr.Name,FindNode);
         end
      else  //文件
        tv.Items.AddChild(node,sr.name);
    until findnext(sr)<>0;
    findclose(sr);
  end;
end;procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
   tv.Items.Clear;
   addTv(edit1.text,nil);
end;end.