unit WinForm1;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data, System.IO, System.Resources, System.Threading;

type
  TWinForm1 = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    components: System.ComponentModel.IContainer;
    TreeView1: System.Windows.Forms.TreeView;
    Button2: System.Windows.Forms.Button;
    TextBox1: System.Windows.Forms.TextBox;
    ImageList1: System.Windows.Forms.ImageList;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);
    procedure TWinForm1_Load(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
    
    
  private
  zmiana: boolean;
    { Private Declarations }
  public
    constructor Create;
    procedure ZapelnijDrzewo(drzewo: Treeview; wezel: TreeNode; katalog: String;czyDodawacPliki: boolean);

  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm1))]

implementation

{$AUTOBOX ON}
{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm1.InitializeComponent;
var
  resources: System.Resources.ResourceManager;
begin
  Self.components := System.ComponentModel.Container.Create;
  resources := System.Resources.ResourceManager.Create(TypeOf(TWinForm1));
  Self.TreeView1 := System.Windows.Forms.TreeView.Create;
  Self.Button2 := System.Windows.Forms.Button.Create;
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.ImageList1 := System.Windows.Forms.ImageList.Create(Self.components);
  Self.SuspendLayout;
  // 
  // TreeView1
  // 
  Self.TreeView1.ImageIndex := -1;
  Self.TreeView1.ImeMode := System.Windows.Forms.ImeMode.NoControl;
  Self.TreeView1.Location := System.Drawing.Point.Create(10, 55);
  Self.TreeView1.Name := 'TreeView1';
  Self.TreeView1.SelectedImageIndex := -1;
  Self.TreeView1.Size := System.Drawing.Size.Create(422, 407);
  Self.TreeView1.TabIndex := 0;
  // 
  // Button2
  // 
  Self.Button2.Location := System.Drawing.Point.Create(374, 18);
  Self.Button2.Name := 'Button2';
  Self.Button2.Size := System.Drawing.Size.Create(58, 27);
  Self.Button2.TabIndex := 2;
  Self.Button2.Text := 'OK';
  Include(Self.Button2.Click, Self.Button2_Click);
  // 
  // TextBox1
  // 
  Self.TextBox1.Location := System.Drawing.Point.Create(10, 18);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.Size := System.Drawing.Size.Create(355, 22);
  Self.TextBox1.TabIndex := 3;
  Self.TextBox1.Text := '';
  // 
  // ImageList1
  // 
  Self.ImageList1.ImageSize := System.Drawing.Size.Create(16, 16);
  Self.ImageList1.ImageStream := (System.Windows.Forms.ImageListStreamer(resources.GetObject('I' +
    'mageList1.ImageStream')));
  Self.ImageList1.TransparentColor := System.Drawing.Color.Transparent;
  // 
  // TWinForm1
  // 
  Self.AutoScale := False;
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 15);
  Self.ClientSize := System.Drawing.Size.Create(441, 472);
  Self.Controls.Add(Self.TextBox1);
  Self.Controls.Add(Self.Button2);
  Self.Controls.Add(Self.TreeView1);
  Self.Name := 'TWinForm1';
  Self.Text := 'FileTreeView (Windows Forms)';
  Include(Self.Load, Self.TWinForm1_Load);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm1.ZapelnijDrzewo(drzewo: Treeview; wezel: TreeNode; katalog: String; czyDodawacPliki: boolean);
var
nowy: TreeNode;
kat: DirectoryInfo;
plik: FileInfo;
listakatalogow,listaplikow: array of string;
i: integer;
begin
try
if wezel=nil then
begin
  kat:=DirectoryInfo.Create(katalog);
  wezel:=drzewo.Nodes.Add(kat.Name);
end;
listakatalogow:=System.IO.directory.getdirectories(katalog);
listaplikow:=System.IO.Directory.GetFiles(katalog);
for i:=0 to length(listakatalogow)-1 do
begin
  kat:=DirectoryInfo.Create(listakatalogow[i]);
  nowy:=TreeNode.Create('['+kat.Name+']');
  wezel.Nodes.Add(nowy);
  ZapelnijDrzewo(drzewo,nowy,kat.FullName,czydodawacpliki);
  kat.Free;
end;
if czydodawacpliki then
for i:=0 to length(listaplikow)-1 do
begin
  plik:=FileInfo.Create(listaplikow[i]);
  wezel.Nodes.Add(plik.Name);
  plik.Free;
end;
except
  drzewo.Nodes.Clear;
  MessageBox.Show('Katalog nie jest dostêpny');
end;
end;

procedure TWinForm1.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm1.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm1.TWinForm1_Load(sender: System.Object; e: System.EventArgs);
begin
  zmiana:=false;
end;

procedure TWinForm1.Button2_Click(sender: System.Object; e: System.EventArgs);
begin
TreeView1.Nodes.Clear;
Self.ZapelnijDrzewo(TreeView1,nil,TextBox1.Text,true);
end;



end.
