■
結局、お気に入りフォルダのURL収集クラスMyFilesは以下のようになりました。
public class MyFiles { private String rootPath_= String.Empty; private IList dirs = new ArrayList(); public MyFiles( String rootPath ){ this.rootPath_ = rootPath; foreach( string sub in Directory.GetDirectories( this.rootPath_) ){ this.dirs.Add(new MyFiles(sub)); } } public string nodeName { get { return this.rootPath_; } } public IList files { get { return (IList) Directory.GetFiles(rootPath_); } } 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; } }
使い方の例としては以下のようになります。
this.treeFaverate = new System.Windows.Forms.TreeView(); private MyFiles myFiles_ = null; { TreeNodeCollection nodes = this.treeFaverate.Nodes; this.boomarkDir_ = Environment.GetFolderPath(Environment.SpecialFolder.Favorites); this.myFiles_ = new MyFiles(this.boomarkDir_); this.treeFaverate.Nodes.Add(this.myFiles_.CreateNode()); }