Exemplo n.º 1
0
            /// <summary>Yield all subdirectories of the supplied path as a text outline.</summary>
            /// <param name="rootPath">Topmost directory.</param>
            /// <param name="fileFilter">Search pattern or *null* for all.</param>
            /// <param name="drawWith">Outline characters.</param>
            /// <param name="order">Output sorting.</param>
            /// <param name="tab">Number of characters to indent per level.</param>
            /// <returns>All subdirectories of the supplied path as a text outline.</returns>
            public static IEnumerable <string> GenerateTextTree(string rootPath, string fileFilter, DrawWith drawWith = DrawWith.Graphic, Ordering order = Ordering.None, int tab = 4)
            {
                var sb = new StringBuilder();

                for (var dv = new DirNode.Vector(rootPath, null, order, drawWith, tab); dv.Advance(); sb.Length = 0)
                {
                    sb.AppendIndent(dv, false);
                    sb.Append(dv.Depth == 0 ? dv.Top.Path : dv.Top.Name);
                    yield return(sb.ToString());

                    if (fileFilter != null)
                    {
                        dv.PregetContents(fileFilter);
                        if (dv.Top.FileInfos.Count > 0)
                        {
                            sb.Length = 0;
                            sb.AppendIndent(dv, true);
                            int indentLength = sb.Length;
                            foreach (var fInfo in dv.Top.FileInfos)
                            {
                                sb.Append(fInfo.Name);
                                yield return(sb.ToString());

                                sb.Length = indentLength;
                            }
                            yield return(sb.ToString());
                        }
                    }
                }
            }
Exemplo n.º 2
0
            /// <summary>Yield all subdirectories of the supplied path.</summary>
            /// <param name="rootPath">Topmost directory.</param>
            /// <param name="fileFilter">Search pattern or *null* for all.</param>
            /// <param name="order">Output sorting.</param>
            /// <returns>All subdirectories of the supplied path as text.</returns>
            public static IEnumerable <string> EnumerateFiles(string rootPath, string fileFilter = null, Ordering order = Ordering.None)
            {
                if (fileFilter == null)
                {
                    fileFilter = "*";
                }

                for (var dv = new DirNode.Vector(rootPath, null, order); dv.Advance();)
                {
                    dv.PregetContents(fileFilter);
                    foreach (var fInfo in dv.Top.FileInfos)
                    {
                        yield return(fInfo.FullName);
                    }
                }
            }