M
Martin
Hi,
I have implemeted a recursive function that basically iterate throught the
entire file system and prints out the entire path of each directory that it
come across.
The only problem is the the directoryinfo objevy does not seem to list
directories in the same order as windows explorer would.
my main function is below but in order to demonstate my point here is a
senarion
image these are directories at the root of the C:/ drive
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
private static void IterateChildren(string dirRoot, StreamWriter stream)
{
try
{
DirectoryInfo info = new DirectoryInfo(dirRoot);
foreach (DirectoryInfo innerInfo in info.GetDirectories())
{
stream.WriteLine(innerInfo.FullName.ToString());
Console.WriteLine(innerInfo.FullName.ToString());
IterateChildren(innerInfo.FullName,stream);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
I have implemeted a recursive function that basically iterate throught the
entire file system and prints out the entire path of each directory that it
come across.
The only problem is the the directoryinfo objevy does not seem to list
directories in the same order as windows explorer would.
my main function is below but in order to demonstate my point here is a
senarion
image these are directories at the root of the C:/ drive
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
1 - level 2 - A
private static void IterateChildren(string dirRoot, StreamWriter stream)
{
try
{
DirectoryInfo info = new DirectoryInfo(dirRoot);
foreach (DirectoryInfo innerInfo in info.GetDirectories())
{
stream.WriteLine(innerInfo.FullName.ToString());
Console.WriteLine(innerInfo.FullName.ToString());
IterateChildren(innerInfo.FullName,stream);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}