PSDirectoryTree

Test Status PowerShell Gallery Version PowerShell Gallery Downloads

PSDirectoryTree is a PowerShell module for visualizing directory structures in a clear, tree-like format.

Supports .gitignore filtering, JSON output, progress indication, and optional file export — making it ideal for documentation, automation, or codebase exploration.


Why?

Manually browsing or documenting large codebases can be messy.

👉 PSDirectoryTree generates a clear, structured tree with filtering, colors, and export options — so you can understand, document, and automate directory layouts quickly.


Features


Installation

Install from PowerShell Gallery:

Install-Module PSDirectoryTree -Scope CurrentUser

📦 View on PowerShell Gallery


Usage

Visual tree in the console

Get-DirectoryTree -RootPath "."

Output as JSON

Get-DirectoryTree -RootPath "." -AsJson

Save tree output to a file

Get-DirectoryTree -RootPath "." -OutputFile ".\tree.txt"

Save JSON structure to file

Get-DirectoryTree -RootPath "." -AsJson -OutputFile ".\structure.json"

Parameters

Parameter Description
RootPath Root directory to scan.
MaxDepth Maximum depth to traverse (default: 100).
Filter Filter output: All, Folders, or Files.
IgnoreGitIgnore Skip .gitignore filtering.
AsJson Output the result as a JSON object.
OutputFile File path to save the output. Works with text or JSON.

Example Tree Output

project-root
├── src
│   ├── index.ts
│   └── app.ts
├── dist
│   └── bundle.js
└── README.md

GitIgnore Integration


JSON Structure

When -AsJson is used, the output looks like:

{
  "Name": "project-root",
  "Path": "C:\\Path\\To\\project-root",
  "Type": "Folder",
  "Children": [
    {
      "Name": "index.html",
      "Path": "C:\\Path\\To\\project-root\\index.html",
      "Type": "File",
      "Children": []
    },
    {
      "Name": "src",
      "Path": "C:\\Path\\To\\project-root\\src",
      "Type": "Folder",
      "Children": [
        {
          "Name": "main.ts",
          "Path": "C:\\Path\\To\\project-root\\src\\main.ts",
          "Type": "File",
          "Children": []
        }
      ]
    }
  ]
}

👉 Perfect for piping into frontend tools, documentation systems, or CI reports.


Output Colors

Type Color
Folder Cyan
.ts Blue
.js Yellow
.css Green
.html Magenta
.json Dark Yellow
Other files Gray

License

Licensed under the MIT License.

Author

Developed and maintained by Vikansys AB (Sweden).
For issues or feature requests, please send us an email.