vieyahn2017 / shellv

shell command test and study
4 stars 1 forks source link

Powershell脚本 - tree #90

Open vieyahn2017 opened 7 months ago

vieyahn2017 commented 7 months ago
Function Get-Tree {
    param(
        [string]$directory = ".",
        [int]$d = 1,
        [switch]$f
    )
    $absolutePath = Resolve-Path -Relative $directory
    Write-Host $absolutePath
    function Recurse-Tree {
        param(
            [string]$currentDir,
            [int]$currentDepth
        )

        $indent = "    " * $currentDepth
        $items = Get-ChildItem -Path $currentDir

        foreach ($item in $items) {
            if ($item.PSIsContainer -or $f) {
                Write-Host ("{0}|-- {1}" -f $indent, $item.Name)

                if ($item.PSIsContainer -and ($currentDepth -lt $d -or $d -eq -1)) {
                    Recurse-Tree -currentDir $item.FullName -currentDepth ($currentDepth + 1)
                }
            }
        }
    }

    Recurse-Tree -currentDir $directory -currentDepth 0
}

New-Alias -Name tree -Value Get-Tree
vieyahn2017 commented 7 months ago

https://blog.csdn.net/qq_51352578/article/details/132701269