Solved

How can i enumerate all subfolders of a folder in registry in TreeView.

Posted on 2006-07-11
8
472 Views
Last Modified: 2010-04-05
Hi.

The title is self-explanatory.

I need to list in a treeview the subfolders (not the subfolders of the subfolders  (Depth=1)) of a path in registry.

Example : ( List SubFolders of    HKEY_USERS\Default )
------------------------------------------
HKEY Users
|->Default
      |-> AppEvents
      |-> Console
      |-> Control Panel
      |-> EHelp
      |-> Environment

------------------------------------------

Thanks in advance :)
0
Comment
Question by:CodedK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 250 total points
ID: 17080321
Hi, here is how you can do it.

var
  Reg : TRegistry;
  s : TStringList;
begin
  Reg := TRegistry.Create;
  s := TStringList.Create;
  Reg.RootKey := HKEY_USERS;
  Reg.OpenKey('.DEFAULT', False);
  Reg.GetKeyNames(s);
  Memo1.Lines.Assign(s);
  s.Free;
  Reg.Free;
end;
0
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 250 total points
ID: 17080343
here is how to do it with ttreeview:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses registry;

procedure addthem(key:HKEY; path:string; treeview1:TTreeView);
var t:TTreeNode; r:tregistry; s:tstringlist; i:integer;
begin
  t:=TreeView1.Items.Add(TreeView1.Items.GetFirstNode,path);
  r:=tregistry.Create;
  r.RootKey:=key;
  if r.OpenKey(path,false) and r.HasSubKeys then
  begin
    s:=tstringlist.create;
    r.GetKeyNames(s);
    for i:=1 to s.count do
      TreeView1.Items.Addchild(t,s[i-1]);
    s.free;
  end;
  r.free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  addthem(HKEY_USERS,'.Default',TreeView1);
end;

end.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080351
Thanks :) ... both

Well if itsnt too much to ask do you know how can i filter those subfolders and list only those...
if they contain a subfolder named "2" ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:atul_parmar
ID: 17080381
After retrieving the list to stringlist you can simply check / search into it.
e..g
s.IndexOf('2'); // will return the index if found -1 otherwise.

OR

var
  Reg : TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_USERS;
  Reg.OpenKey('.DEFAULT', False);
  if Reg.KeyExists('2') then
     ShowMesasage('The key exists');
  Reg.Free;
end;
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080398
Thanks :)

I'll split the points if you dont mind...
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17080404
That's fine.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080603
Ciuly how can i insert those values to an allready existing item in the treeview ?
0
 
LVL 28

Expert Comment

by:2266180
ID: 17080628

TreeView1.Items.Addchild(existing node,text)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 48
CheckListBox usage 3 83
can i put an image from resource into image tag ? 6 32
Browsing a TTreeView in Delphi 5 32
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question