Created
August 16, 2012 11:33
-
-
Save SamWM/3369500 to your computer and use it in GitHub Desktop.
Directory Recursion (using memoization)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
Queue<string> directories = new Queue<string>(Directory.GetDirectories(@"C:\Windows\system32\")); | |
do | |
{ | |
string dir = directories.Dequeue(); | |
Console.WriteLine("Directory: " + dir); | |
try | |
{ | |
string[] subdirs = Directory.GetDirectories(dir); | |
foreach(string subdir in subdirs) | |
{ | |
directories.Enqueue(subdir); | |
} | |
} | |
catch(UnauthorizedAccessException ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
while(directories.Count > 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment