I can get hold of the top most Parent...
So there is a single root to this tree?
I'm going to assume that's the case. :)
Sorry, this is in C# (my VB is very weak), but hopefully you can follow what I'm doing:
Dictionary<string, List<string>> Hierarchy = new Dictionary<string, List<string>>();
foreach (string line in File.ReadLines(filepath))
{
if (string.IsNullOrWhiteSpace(line))
continue;
string[] parentChild = line.Split((char[]) null, StringSplitOptions.RemoveEmptyEntries);
if (parentChild.Length != 2)
{
continue;
}
string parent = parentChild[0];
List<string> children;
if (!Hierarchy.TryGetValue(parent, out children))
{
children = new List<string>();
Hierarchy[parent] = children;
}
children.Add(parentChild[1]);
}
Now you can recursively traverse the
Hierarchy
starting with your known root parent.
Walk down the list of children of that parent recursively getting them from the
Hierarchy
using the
Hierarchy.TryGetValue(...)
as above. If that returns false, then that name is a "leaf".