How would I get all sub directories in the base master directory (C drive).
I also need to use this for the registry (please I know what I am doing)
How would I get all sub directories in the base master directory (C drive).
I also need to use this for the registry (please I know what I am doing)
Did you know the FAQ is searchable?
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
well to bad the faq doesn't have any file recursion for C#.
I'm sure the c++ code is convertable but I really don't know c++ as good as C#.
p.s this is the C board not the C# board
Last edited by prog-bman; 03-22-2005 at 08:16 PM.
Woop?
can someone move this please, I feel like an idoit.
please move this to C# board.
thank you for your patients with me.
In other words, you can only get away with being a smart ass if you're not a dumb ass.
Quzah.
Hope is the first step on the road to disappointment.
Moved to C# board as requested.
However you may want to provide a little bit more detail.
I want to collect the names of all of the directorys in the, lets say, C drive. From there I can get the names of the files, and any other info I need.
That is as clear as I can get it.
Simple recursion:Originally Posted by Rune HunterCode:using System; using System.Collections; using System.IO; namespace GetDirs { class entry { static void Main(string[] args) { Test test = new Test(); test.GetDirs(@"C:\"); test.DumpDirs(); } } class Test { private ArrayList directories = new ArrayList(); public void GetDirs(string home) { string[] dirs1 = Directory.GetDirectories(home); foreach (string dir in dirs1) { directories.Add(dir); try { string[] dirs2 = Directory.GetDirectories(dir); if (dirs2.Length > 0) GetDirs(dir); } catch { } } } public void DumpDirs() { foreach (object obj in directories) Console.WriteLine((string)obj); } } }
And here I modified the above example to do the same thing with registry keys:Code:using System; using System.Collections; using Microsoft.Win32; namespace GetReg { class entry { static void Main(string[] args) { Test test = new Test(); test.GetRegKeys(Registry.ClassesRoot); test.GetRegKeys(Registry.CurrentUser); test.GetRegKeys(Registry.LocalMachine); test.GetRegKeys(Registry.Users); test.GetRegKeys(Registry.CurrentConfig); test.DumpRegKeys(); } } class Test { private ArrayList regkeys = new ArrayList(); public void GetRegKeys(RegistryKey homekey) { string[] subkeys = homekey.GetSubKeyNames(); foreach (string subkey in subkeys) { try { regkeys.Add(homekey.Name + '\\' + subkey); RegistryKey subkey2 = homekey.OpenSubKey(subkey); if (subkey2.SubKeyCount > 0) GetRegKeys(subkey2); subkey2.Close(); } catch { } } } public void DumpRegKeys() { foreach (object obj in regkeys) Console.WriteLine((string)obj); } } }
I don't see where test is coming from? It isn't in Visual C# 2005 at least.
Edit: nvm I see now.
omg thank you so much! I am going to study and learn how this works now!
1 problem, it says I don't have access to the registry but I am full adminster and have full permisions on this computer. Why can't I with .net?
Edit: Hmm I guess my program I made before just was bad or somtin... it works fine now.
Last edited by Rune Hunter; 03-24-2005 at 06:56 PM.
ok so how would I get the value of the key it is in as well. I have tried many, many things but I got no results.
http://msdn.microsoft.com/library/de...namestopic.asp + foreach + http://msdn.microsoft.com/library/de...valuetopic.aspOriginally Posted by Rune Hunter
Also, do a little search on recursion to understand why it works.
alright I should do some research by just by looking at it I can grasp how it works.
And thank you, I was alot confused on C# registry values. The registry can be confusing at times.