Powershell模拟实现Linux下的tree命令

Powershell模拟实现Linux下的tree命令

代码

环境: P o w e r s h e l l   7 Powershell\ 7 Powershell 7

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

将上述代码拷贝到"C:\Users\${username}\Documents\PowerShell\profile.ps1"

如果是 P o w e r s h e l l   5 Powershell\ 5 Powershell 5

拷贝到"C:\Users\${username}\Documents\WindowsPowerShell\profile.ps1"

效果

运行:

tree D:\py-projects -d 1

打印效果

D:\py-projects
|-- CartPole-actor-critic-based
    |-- __pycache__
    |-- .vscode
    |-- A2C
    |-- PPO
    |-- REINFORCE
    |-- result
|-- checkpoints
|-- cliff_walk
|-- crack_detection_mp
    |-- .vscode
    |-- backend
    |-- model_deploy
    |-- mp-weixin
|-- CustomEnv
    |-- __pycache__
    |-- .vscode
    |-- result
|-- deep-in-python-use
|-- faster-rcnn-deploy
    |-- .vscode
    |-- checkpoints
    |-- datasets
    |-- flagged
    |-- mmdeploy
    |-- mmdeploy_model
    |-- mmdetection
|-- GridWorld-value-based
    |-- .idea
    |-- .vscode
    |-- A2C
    |-- backup
    |-- DQN
    |-- REINFORCE
|-- gym-examples
    |-- gym_examples
|-- open-resume
    |-- public
    |-- src
|-- Pendulum-actor-critic-based
    |-- .vscode
    |-- bkp
    |-- DDPG
    |-- result
    |-- SAC
    |-- TD3
|-- pycharm-projects
    |-- .idea
|-- QQFlacMusicDownloader
    |-- .idea
    |-- flaskSystem
    |-- md
    |-- music
    |-- WebSourceCode
|-- reinforcejs
    |-- agentzoo
    |-- external
    |-- img
    |-- lib
|-- RL_test
    |-- __pycache__
|-- RL-notes
|-- stitp_deploy
    |-- checkpoints
    |-- mmdeploy
    |-- mmdeploy_model
    |-- mmdeploy-1.2.0-windows-amd64-cuda11.3
    |-- mmdetection
    |-- mmpretrain
    |-- work_dir
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值