Skip to content

Repository files navigation

SharpTree

SharpTree is a tool designed to construct and visualize the filesystem tree structure.

Table of Contents

Features

  • PowerShell Integration: Easily importable into PowerShell 5.1 or 7 scripts for automation and scripting tasks.
  • Multi-Targeted: Compatible with both modern .NET environments (.NET 8) and legacy systems via .NET Framework 4.8 for PowerShell 5.1.

Prerequisites

  • .NET 8 SDK: Required for building the project. Download Here
  • PowerShell 5.1 or 7: Available by default on Windows systems.
  • Operating System: Windows.

Installation

  1. Clone the Repository

    git clone https://github.com/isaiahduarte/SharpTree.git
    cd SharpTree
  2. Restore Dependencies

    Ensure all necessary NuGet packages are restored.

    dotnet restore
  3. Build the Project

    Follow the Building SharpTree section to generate the necessary DLLs.

Building SharpTree

  1. Ensure .NET 8 SDK is Installed

    Download and install the latest .NET 8 SDK if you haven't already.

  2. Navigate to the Project Directory

    cd SharpTree
  3. Build the Project

    Execute the following command to build for both target frameworks:

    dotnet publish
  4. Locate the Generated DLLs

    After a successful build, the DLLs will be located in:

    \bin\SharpTree\publish
    \bin\SharpTree.Core\publish
    

Using SharpTree in PowerShell

Integrate SharpTree into your PowerShell scripts by importing the compatible DLL and utilizing its methods to build and display filesystem trees.

Importing the DLL

Depending if you are using PowerShell 5.1 or 7, you will need to import the corresponding DLL:

Powershell 5.1

$dllPath = "C:\Path\To\SharpTree\bin\SharpTree.Core.Powershell\SharpTree.Core.Powershell.dll"

Powershell 7

$dllPath = "C:\Path\To\SharpTree\bin\SharpTree.Core\publish\SharpTree.Core.Powershell.dll"

Note: Powershell 7 is more efficient and recommended for use.

Import the SharpTree DLL

Use the Add-Type cmdlet to load the assembly:

# Import the DLL
Add-Type -Path $dllPath

Example Usage

# See which version of PowerShell is running
if ($PSVersionTable.PSVersion.Major -eq 5) {
   $dllPath = "C:\Path\To\SharpTree\bin\SharpTree.Core.Powershell\SharpTree.Core.Powershell.dll"
   exit
} elseif ($PSVersionTable.PSVersion.Major -eq 7) {
   $dllPath = "C:\Path\To\SharpTree\bin\SharpTree.Core\SharpTree.Core.dll"
} else {
   Write-Host "Unsupported PowerShell version"
   exit
}

# Load the assembly
Add-Type -Path $dllPath -PassThru

# Get the root node                                      #Path #MinSize #MaxDepth
$Node = [SharpTree.Core.Services.FileSystemReader]::Read($ENV:USERPROFILE, 1024, -1)

# Save node to JSON
$Node.SaveToJson(C:\report.json)

# Display Node
$Node.Show()

# Load From JSON
$Node = [SharpTree.Core.Services.JsonNode]::LoadFromJson(C:\report.json)
Test.webm

Contributing

Contributions are welcome! To contribute to SharpTree, follow these steps:

  1. Fork the Repository

    Click the "Fork" button on the repository page to create a personal copy.

  2. Clone Your Fork

    git clone https://github.com/IsaiahDuarte/SharpTree.git
    cd SharpTree
  3. Create a New Branch

    git checkout -b feature/YourFeatureName
  4. Make Your Changes

    Implement your feature or bug fix.

  5. Commit Your Changes

    git commit -m "Add description of your feature or fix"
  6. Push to Your Fork

    git push origin feature/YourFeatureName
  7. Open a Pull Request

    Go to the original repository and create a pull request detailing your changes.

About

A tool similar to TreeSize but in C#

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages