Пример #1
0
        /// <summary>
        /// Rebuilds the directory tree
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        public TreeNode[] UpdateDirectoryTree(IDirectoryProvider path = null)
        {
            if (path == null)
            {
                path = _directoryProvider;
            }

            List <TreeNode> nodeList = new List <TreeNode>();

            var nodeName = new StringBuilder();

            nodeName.Append(path.Name);
            nodeName.AppendFormat(" ({0})", path.EnumerateFiles().Count());
            var node = new TreeNode(nodeName.ToString())
            {
                Tag = path.FullName
            };

            foreach (var directory in path.GetDirectories())
            {
                if (!directory.Name.StartsWith("."))
                {
                    var childNodes = UpdateDirectoryTree(directory);
                    node.Nodes.AddRange(childNodes);
                }
            }

            nodeList.Add(node);
            TreeNode[] nodeArr = nodeList.ToArray();

            return(nodeArr);
        }
Пример #2
0
        /// <summary>
        /// Rebuilds the directory tree
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        public TreeNode[] UpdateDirectoryTree(IDirectoryProvider path = null)
        {
            if (path == null)
            {
                path = _directoryProvider;
            }

            List<TreeNode> nodeList = new List<TreeNode>();

            var nodeName = new StringBuilder();
            nodeName.Append(path.Name);
            nodeName.AppendFormat(" ({0})", path.EnumerateFiles().Count());
            var node = new TreeNode(nodeName.ToString()) { Tag = path.FullName };

            foreach (var directory in path.GetDirectories())
            {
                if (!directory.Name.StartsWith("."))
                {
                    var childNodes = UpdateDirectoryTree(directory);
                    node.Nodes.AddRange(childNodes);
                }
            }

            nodeList.Add(node);
            TreeNode[] nodeArr = nodeList.ToArray();

            return nodeArr;
        }