Advertisement
justinooo

PowerShell 'Show-Tree' function ('tree' alternative)

Jun 7th, 2024 (edited)
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Show-Tree {
  2.     param(
  3.         [Parameter(Mandatory=$false)]
  4.         [string]$Path = (Get-Location).Path,
  5.         [string]$Indent = ""
  6.     )
  7.  
  8.     # Add more as needed
  9.     $excludeDirs = @('node_modules', '__pycache__', 'venv')
  10.  
  11.     $directories = Get-ChildItem -Path $Path -Directory | Where-Object { $excludeDirs -notcontains $_.Name }
  12.  
  13.     $files = Get-ChildItem -Path $Path -File
  14.  
  15.     foreach ($file in $files) {
  16.         "$Indent$file"
  17.     }
  18.  
  19.     foreach ($directory in $directories) {
  20.         "$Indent$($directory.Name)/"
  21.         Show-Tree -Path $directory.FullName -Indent "$Indent    "
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement