There are a few issues here. First, the fields in the FileTree class are private -- and they should be. However, you'll need to create public properties or methods to allow access to them from outside the class.
Second, the List<FileTree> field does not have a name. The compiler will catch that error when you try building the project, so that one won't go unnoticed for long.
Third, it would be beneficial for you to create a constructor that takes the 'node' as a parameter.
With all that said, I think it may be easier to understand if you change the names of some of the items in your code. Think of any item in the file system directory structure as a node because that's a good conceptual model. Here's a skeleton class called Node written in C# 3.0 (previous versions do not support automatic properties) with a convenience property for determining if the node is a file or folder:
Code:
class Node
{
public Node(string path)
{
if (System.IO.Directory.Exists(path))
{
this.IsFolder = true;
this.Children = new List<Node>();
}
else if (!System.IO.File.Exists(path))
throw new IOException("File or directory does not exist.");
this.Path = path;
}
public List<Node> Children { get; private set; }
public bool IsFolder { get; private set; }
public string Path { get; private set; }
}
You could add more logic to populate the node's children internally, but it appears that you want to do that externally. I don't know that one way is really better than the other without knowing exactly how you're intending to use it. Regardless, either way will work.