Exemple #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());
                        }
                    }
                }
            }
Exemple #2
0
 /// <summary>Yield all subdirectories of the supplied path.</summary>
 /// <param name="rootPath">Topmost directory.</param>
 /// <param name="filter">Search pattern or *null* for all.</param>
 /// <param name="order">Output sorting.</param>
 /// <returns>All subdirectories of the supplied path as <see cref="DirectoryInfo"/> instances.</returns>
 public static IEnumerable <DirectoryInfo> EnumerateDirectoriesForInfo(string rootPath, string filter = null, Ordering order = Ordering.None)
 {
     for (var dv = new DirNode.Vector(rootPath, filter, order); dv.Advance();)
     {
         yield return(dv.Top.dirInfos[dv.Top.Index]);
     }
 }
Exemple #3
0
 /// <summary>Yield all subdirectories of the supplied path.</summary>
 /// <param name="rootPath">Topmost directory.</param>
 /// <param name="filter">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> EnumerateDirectories(string rootPath, string filter = null, Ordering order = Ordering.None)
 {
     for (var dv = new DirNode.Vector(rootPath, filter, order); dv.Advance();)
     {
         yield return(dv.Top.Path);
     }
 }
Exemple #4
0
        /// <summary>Appends an appropriate number of spaces to this instance.</summary>
        /// <param name="sb">Instance to append to.</param>
        /// <param name="dv">Path to a directory node.</param>
        /// <param name="forFiles">*true* if files are output, else *false*.</param>
        /// <returns>The <see cref="StringBuilder"/> instance.</returns>
        public static StringBuilder AppendIndent(this StringBuilder sb, DirNode.Vector dv, bool forFiles)
        {
            var topIx = dv.Count - 1;

            if (!forFiles && dv[topIx].Index < 0)
            {
                --topIx;
            }

            for (var ix = 1; ix <= topIx; ++ix)
            {
                if (!forFiles && ix == topIx)
                {
                    sb.Append(dv[ix].IsLast ? dv.UpRight : dv.UpDownRight);
                    for (var jx = 1; jx < dv.TabSize; ++jx)
                    {
                        sb.Append(dv.LeftRight);
                    }
                }
                else
                {
                    sb.Append(dv[ix].IsLast ? ' ' : dv.UpDown);
                    for (var jx = 1; jx < dv.TabSize; ++jx)
                    {
                        sb.Append(' ');
                    }
                }
            }

            return(sb);
        }
Exemple #5
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);
                    }
                }
            }