justinooo icon

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

justinooo | PRO | 06/25/24 09:08:09 PM UTC (Edited) | 0 ⭐ | 7271 👁️ | Never ⏰ | []
PowerShell |

620 B

|

None

|

0 👍

/

0 👎

function Show-Tree {
    param(
        [Parameter(Mandatory=$false)]
        [string]$Path = (Get-Location).Path,
        [string]$Indent = ""
    )
 
    # Add more as needed
    $excludeDirs = @('node_modules', '__pycache__', 'venv')
 
    $directories = Get-ChildItem -Path $Path -Directory | Where-Object { $excludeDirs -notcontains $_.Name }
 
    $files = Get-ChildItem -Path $Path -File
 
    foreach ($file in $files) {
        "$Indent$file"
    }
 
    foreach ($directory in $directories) {
        "$Indent$($directory.Name)/"
        Show-Tree -Path $directory.FullName -Indent "$Indent    "
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎