|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Precio.Collections;
namespace Precio.IO.Collection
{
/// <summary>
///
/// </summary>
/// <author>Martin Dahlstedt 2006 (m_dahlstedt@hotmail.com)</author>
[Serializable()]
public sealed class FileSystemTree : Tree<FileSystemNodeValue>
{
private DirectoryInfo _rootFolder;
/// <summary>
/// Constructor for FileSystemTree.
/// </summary>
/// <param name="rootFolder">Path to the root folder.</param>
public FileSystemTree(DirectoryInfo rootFolder)
: base(new FileSystemNodeValue(rootFolder))
{
_rootFolder = rootFolder;
}
/// <summary>
///
/// </summary>
protected override void BuildIndexInternal()
{
this.BuildIndex(_rootFolder, base.RootNode);
}
/// <summary>
///
/// </summary>
/// <param name="directory"></param>
/// <param name="walkingTreeNode"></param>
private void BuildIndex(DirectoryInfo directory, TreeNode<FileSystemNodeValue> walkingTreeNode)
{
String relativePath = directory.FullName.Substring(_rootFolder.FullName.Length);
foreach (DirectoryInfo childDirectory in directory.GetDirectories())
{
FileSystemNodeValue directoryNode = new FileSystemNodeValue(childDirectory);
base.AddLast(walkingTreeNode, directoryNode);
this.BuildIndex(childDirectory, walkingTreeNode.LastChild.Value);
}
foreach (FileInfo childFile in directory.GetFiles(@"*.*"))
{
FileSystemNodeValue fileNode = new FileSystemNodeValue(childFile);
base.AddLast(walkingTreeNode, fileNode);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.