PSDirectoryTree
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.
- Plain
dir
/ls
outputs are too noisy - File explorers don’t give a shareable “snapshot”
- Keeping README trees up to date is tedious
👉 PSDirectoryTree generates a clear, structured tree with filtering, colors, and export options — so you can understand, document, and automate directory layouts quickly.
Features
- 📂 Tree view of any directory
- 🙈 Honors
.gitignore
rules (disable with-IgnoreGitIgnore
) - 📊 JSON output support (
-AsJson
) - 💾 Save output to file with
-OutputFile
- 🎨 Color-coded output for common file types
- ⏳ Built-in progress feedback (
Write-Progress
)
Installation
Install from PowerShell Gallery:
-Module PSDirectoryTree -Scope CurrentUser Install
Usage
Visual tree in the console
-DirectoryTree -RootPath "." Get
Output as JSON
-DirectoryTree -RootPath "." -AsJson Get
Save tree output to a file
-DirectoryTree -RootPath "." -OutputFile ".\tree.txt" Get
Save JSON structure to file
-DirectoryTree -RootPath "." -AsJson -OutputFile ".\structure.json" Get
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
- Per-directory parsing of
.gitignore
- Respects wildcards, trailing slashes, and folder patterns
- Use
-IgnoreGitIgnore
to disable filtering entirely
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.