Last active
October 28, 2025 05:08
-
-
Save arenagroove/e0c5d165435c706de2eacf0eb3668c7f to your computer and use it in GitHub Desktop.
Pretty folder tree generator for Windows PowerShell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Generates a clean, Unicode-formatted directory tree starting | |
| from the current folder and writes it to a text file named | |
| <foldername>_structure.txt. | |
| You can specify file extensions to exclude (e.g., .txt, .log, .tmp). | |
| Usage: | |
| 1. Save as show-tree.ps1 | |
| 2. Open PowerShell in any folder | |
| 3. Run: | |
| powershell -ExecutionPolicy Bypass -File .\show-tree.ps1 | |
| #> | |
| function show-tree { | |
| param ( | |
| [string]$path = ".", | |
| [string]$prefix = "", | |
| [string[]]$excludeExtensions = @() | |
| ) | |
| # Get subdirectories | |
| $dirs = Get-ChildItem -LiteralPath $path -Directory -ErrorAction SilentlyContinue | |
| # Get files and filter out excluded extensions | |
| $files = Get-ChildItem -LiteralPath $path -File -ErrorAction SilentlyContinue | Where-Object { | |
| $ext = [System.IO.Path]::GetExtension($_.Name) | |
| $excludeExtensions -notcontains $ext | |
| } | |
| # Combine and sort | |
| $items = $dirs + $files | Sort-Object PSIsContainer, Name | |
| # Print the structure recursively | |
| for ($i = 0; $i -lt $items.Count; $i++) { | |
| $item = $items[$i] | |
| $isLast = ($i -eq $items.Count - 1) | |
| $marker = if ($isLast) { "└── " } else { "├── " } | |
| Write-Output "$prefix$marker$($item.Name)" | |
| if ($item.PSIsContainer) { | |
| $nextPrefix = if ($isLast) { "$prefix " } else { "$prefix│ " } | |
| show-tree -path $item.FullName -prefix $nextPrefix -excludeExtensions $excludeExtensions | |
| } | |
| } | |
| } | |
| # === User configuration === | |
| $root = Split-Path (Get-Location) -Leaf | |
| $exclude = @(".txt", ".log", ".tmp") # Add extensions you want to skip here | |
| $outputFile = "${root}_structure.txt" | |
| # === Execution === | |
| Write-Output $root | Out-File $outputFile -Encoding UTF8 | |
| show-tree -excludeExtensions $exclude | Out-File $outputFile -Append -Encoding UTF8 | |
| Write-Host "Folder structure saved to '$outputFile'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment