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/lsoutputs 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
.gitignorerules (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:
Install-Module PSDirectoryTree -Scope CurrentUserUsage
Visual tree in the console
Get-DirectoryTree -RootPath "."Output as JSON
Get-DirectoryTree -RootPath "." -AsJsonSave 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
- Per-directory parsing of
.gitignore - Respects wildcards, trailing slashes, and folder patterns
- Use
-IgnoreGitIgnoreto 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.