TreeView组件遍历磁盘目录

unit treeview;

interface

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

type
  TfrmMain = class(TForm)
    DriveComboBox1: TDriveComboBox;
    dirlst: TDirectoryListBox;
    tv: TTreeView;
    procedure DLBChange(Sender: TObject);
  private
    { Private declarations }
    procedure myfind(Bnode:TTreeNode);
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;
  directorynote,filenode:TTreeNode;
implementation

{$R *.dfm}
procedure TfrmMain.DLBChange(Sender: TObject);
begin
tv.Items.Clear;
myfind(directorynote);
end;

procedure TfrmMain.myfind(Bnode: TTreeNode);
var
  sr:TSearchRec;
  Err:Integer;
begin
  Err := FindFirst('*.*',$37,sr);
  while(Err=0)do
  begin
     if(sr.Name[1]<>'.')then
         begin
           if(sr.Attr and faDirectory)=0 then
           begin
             tv.Items.AddChildFirst(bnode,sr.Name);
           end;

           if(sr.Attr and faDirectory)=faDirectory then
           begin
             ChDir(sr.Name);
             Application.ProcessMessages;
             myfind(filenode);
             ChDir('..');
           end;
         end;
         Err :=FindNext(sr);
  end;
end;
end.

TreeView组件遍历磁盘目录_第1张图片

你可能感兴趣的:(TreeView组件遍历磁盘目录)