お気に入りを取り込むツリービュー

ファイル名:Classes\Util.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
using System.Xml;
using System.Windows.Forms;

namespace ABCS.Classes
{
    class Util
    {
    }
    public class MyFiles {
        private String rootPath_= String.Empty;
        private IList dirs = new ArrayList();

        public MyFiles( String rootPath ){
            this.rootPath_ = rootPath;
            try
            {
                foreach (string sub in Directory.GetDirectories(this.rootPath_))
                {
                    this.dirs.Add(new MyFiles(sub));
                }
            }
            catch (Exception excp)
            {
            }
        }

        public string nodeName
        {
            get
            {
                return this.rootPath_;
            }

        }

        public IList files {
            get 
            {
                IList ret = null;
                try
                {
                    ret = Directory.GetFiles(rootPath_);
                }
                catch (Exception excp)
                {
                    return (IList) ( new List() );
                }

                return ret;
            }
        }

        public IList MyDirs
        {
            get
            {
                return (IList)this.dirs;
            }
        }

        private string getFileName(string fullName)
        {
            char sep = { '\\','/' };

            string ary = fullName.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            return ary[ary.Length - 1];
        }
        public TreeNode CreateNode()
        {
            TreeNode rootNode = new TreeNode(this.getFileName(this.nodeName));
            TreeNodeCollection nodes = rootNode.Nodes;

            foreach (string file in this.files)
            {
                nodes.Add(new TreeNode(this.getFileName(file)));
            }
            foreach (MyFiles sub in this.dirs)
            {
                nodes.Add(sub.CreateNode());
            }

            return rootNode;
        }
    }

}