๐งพ PSDirectoryTree ๐
PSDirectoryTree is a PowerShell module for
visualizing directory structures in a clear, tree-like format. It
supports .gitignore
filtering, JSON output, progress
indication, and optional file export โ making it ideal for
documentation, automation, or codebase exploration.
โจ Features
- Tree view of any directory
- Honors
.gitignore
rules by default (optional) - JSON output support (
-AsJson
) - Write to file with
-OutputFile
- Color-coded output for common file types
- Built-in progress feedback via
Write-Progress
๐ง Installation
Install the module from PowerShell Gallery:
-Module PSDirectoryTree -Scope CurrentUser Install
๐ฆ View on PowerShell Gallery
๐ Usage Examples
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 |
The 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 Output
project-root
โโโ src
โ โโโ index.ts
โ โโโ app.ts
โโโ dist
โ โโโ bundle.js
โโโ README.md
๐ GitIgnore Integration
- Per-directory parsing of
.gitignore
- Respects common patterns (wildcards, trailing slashes, folders).
- Use
-IgnoreGitIgnore
to disable filtering entirely.
๐งพ JSON Structure
When -AsJson
is used, the output will look like
this:
{
"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": []
}
]
}
]
}
This format is ideal for further processing, such as feeding 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
This project is licensed under the MIT License.
Maintained by Vikansys AB