TreeCreator 1.0.8

dotnet add package TreeCreator --version 1.0.8
                    
NuGet\Install-Package TreeCreator -Version 1.0.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TreeCreator" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TreeCreator" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="TreeCreator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TreeCreator --version 1.0.8
                    
#r "nuget: TreeCreator, 1.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=TreeCreator&version=1.0.8
                    
Install TreeCreator as a Cake Addin
#tool nuget:?package=TreeCreator&version=1.0.8
                    
Install TreeCreator as a Cake Tool

TreeCreator

NuGet License: MIT

A flexible and powerful .NET library for generating directory tree representations with advanced filtering capabilities. Similar to the classic tree command-line utility but with more configuration options and a fluent API.

Features

  • Generate ASCII/text tree representations of directory structures
  • Exclude specific directories or file extensions
  • Include only specific directories or file extensions
  • Fluent API for easy configuration
  • Customizable output format
  • Support for modern .NET applications

Installation

Package Manager

Install-Package TreeCreator

.NET CLI

dotnet add package TreeCreator

PackageReference

<PackageReference Include="TreeCreator" Version="1.0.3" />

Quick Start

using TreeCreator;

// Create a new tree generator
var treeCreator = TreeCreatorFactory.Create();

// Generate a tree for the specified directory
var result = treeCreator.Generate("C:/Projects/MyProject");

// Display the tree
Console.WriteLine(result.ToString());

Usage Examples

Basic Usage

using TreeCreator;

// Create a new tree generator
var treeCreator = TreeCreatorFactory.Create();

// Generate a tree for the specified directory
var result = treeCreator.Generate("C:/Projects/MyProject");

// Display the tree
Console.WriteLine(result.ToString());

Excluding Directories

var treeCreator = TreeCreatorFactory.Create()
    .ExcludeDirectories("bin", "obj", "node_modules", ".git");

var result = treeCreator.Generate("C:/Projects/MyProject");

Excluding File Extensions

var treeCreator = TreeCreatorFactory.Create()
    .ExcludeExtensions(".dll", ".exe", ".pdb");

var result = treeCreator.Generate("C:/Projects/MyProject");

Including Only Specific Directories

var treeCreator = TreeCreatorFactory.Create()
    .IncludeOnlyDirectories("src", "tests", "docs");

var result = treeCreator.Generate("C:/Projects/MyProject");

Including Only Specific File Extensions

var treeCreator = TreeCreatorFactory.Create()
    .IncludeOnlyExtensions(".cs", ".csproj", ".md");

var result = treeCreator.Generate("C:/Projects/MyProject");

Combining Multiple Filters

var treeCreator = TreeCreatorFactory.Create()
    .ExcludeDirectories("bin", "obj")
    .IncludeOnlyExtensions(".cs", ".csproj");

var result = treeCreator.Generate("C:/Projects/MyProject");

Working with the Result

var treeCreator = TreeCreatorFactory.Create();
var result = treeCreator.Generate("C:/Projects/MyProject");

// Get the string representation
string treeString = result.ToString();

// Access individual lines
foreach (var line in result.Lines)
{
    Console.WriteLine($"Line: {line}");
}

// Save to a file
File.WriteAllText("tree-output.txt", result.ToString());

API Reference

TreeCreatorFactory

Static factory for creating instances of ITreeCreator.

public static class TreeCreatorFactory
{
    public static ITreeCreator Create();
}

ITreeCreator

Interface defining the core functionality of the tree generator.

public interface ITreeCreator
{
    ITreeCreator ExcludeDirectories(params string[] directoryNames);
    ITreeCreator ExcludeExtensions(params string[] extensions);
    ITreeCreator IncludeOnlyDirectories(params string[] directoryNames);
    ITreeCreator IncludeOnlyExtensions(params string[] extensions);
    TreeResult Generate(string? rootPath);
}

TreeResult

Represents the result of a directory tree generation operation.

public class TreeResult
{
    public TreeResult(string rootPath);
    public void AppendLine(string line);
    public IReadOnlyList<string> Lines { get; }
    public override string ToString();
}

TreeCreatorOptions

Configuration options for the tree generator.

public class TreeCreatorOptions
{
    public HashSet<string> ExcludedDirectories { get; }
    public HashSet<string> ExcludedExtensions { get; }
    public HashSet<string> IncludedDirectories { get; }
    public HashSet<string> IncludedExtensions { get; }
}

Example Output

C:/Projects/MyProject/
├── src/
│   ├── TreeCreator/
│   │   ├── DefaultTreeCreator.cs
│   │   ├── Interfaces/
│   │   │   └── ITreeCreator.cs
│   │   ├── Models/
│   │   │   ├── TreeCreatorOptions.cs
│   │   │   └── TreeResult.cs
│   │   └── TreeCreatorFactory.cs
│   └── TreeCreator.csproj
├── tests/
│   ├── TreeCreator.Tests/
│   │   ├── DefaultTreeCreatorTests.cs
│   │   └── TreeResultTests.cs
│   └── TreeCreator.Tests.csproj
└── README.md

Requirements

  • .NET 8.0 or higher

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Acknowledgments

  • Inspired by the classic Unix/Linux tree command
  • Developed with love for the .NET community
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8 185 5/14/2025
1.0.7 187 5/14/2025
1.0.6 248 5/12/2025
1.0.5 212 5/12/2025
1.0.4 194 5/12/2025
1.0.3 113 5/11/2025
1.0.2 117 5/11/2025
1.0.1 120 5/11/2025
1.0.0 55 5/3/2025

- Initial release of TreeCreator.